Current location: Hot Scripts Forums » General Web Coding » JavaScript » how to read a web page content to a variable?


how to read a web page content to a variable?

Reply
  #1 (permalink)  
Old 11-30-03, 10:29 PM
wings01234 wings01234 is offline
New Member
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
how to read a web page content to a variable?

Is there a way to read the content of a web page to a variable using javascript, but don't open that web page?
Somthing like PHP's:

$url="http://www.somesite.com";
$content = join('', file($url));

Or other client-side script can?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-01-03, 03:28 PM
CarnieLtd CarnieLtd is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
As far as I am aware you will need to open the webpage to read its contents with either innerTEXT or innerHTML. If you don't want your user to see it being opened the best way to hide it would be to use an invisible iframe that loads the page. They still maybe able to see it loading by the status bar but it will never show on the website.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-01-03, 09:05 PM
wings01234 wings01234 is offline
New Member
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Cound you show me some exmple code? Thanks a lot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-14-03, 12:37 PM
psyon psyon is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
There is no way to do this if the content you wish to retrieve is on another site. Browsers do not allow cross site scripting for security reasons.

If the content is on the same sites, then it is possible by using an iframe or normal frames

Assuming you have an iframe
Code:
<iframe name="loader" height=0 width=0 style="visibility: hidden">
Then once a page is loaded into the iframe you should be able to get the contents with
Code:
var html = document.loader.innerHTML;
I might have teh document.loader.innterHTML part wrong, I have a script at my home computer that I use to load variables from a text file that does this. If that is not the correct way, I will post working code if no one else has by the time I get home.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 01-13-04, 09:27 AM
tekola tekola is offline
New Member
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Read text from an Iframe

This is a follow-up. This code doesn't appear to work.
Assuming you have an iframe

<iframe name="loader" height=0 width=0 style="visibility: hidden">

Then once a page is loaded into the iframe you should be able to get the contents with

var html = document.loader.innerHTML;



I get the Iframe content but nothing in html.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Only allowing original referrer to access a page fixafone123 PHP 3 05-28-04 05:42 AM
Call a variable name dynamically Kenrette ASP 2 11-12-03 10:48 AM
echo foriegn html in static page fergusom Everything Java 4 11-10-03 03:35 AM
preload an asp page Gurrutello ASP 1 06-24-03 09:12 PM
xhtml + css rockerBOO CSS 6 06-20-03 03:47 PM


All times are GMT -5. The time now is 09:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.