aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Retrive Web Page via Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Retrive Web Page via Javascript" Watch "Retrive Web Page via Javascript" New topic
Author

Retrive Web Page via Javascript

Kevin Cornwell
Ranch Hand

Joined: Feb 01, 2005
Posts: 34
This should be simple but I'm having trouble...

How do I get a web page with javascript and assign the entire page contents to a javascript variable?



<a href="http://www.kevincornwell.com" target="_blank" rel="nofollow">http://www.kevincornwell.com</A>
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you want the content of the current page, then all you need to do is: var content = document.body.innerHTML;

If you want another html page, then the only way you can do it with JavaScript is if you are grabbing a page on the same domain and that your browser supports AJAX or iframes.

Eric
Kevin Cornwell
Ranch Hand

Joined: Feb 01, 2005
Posts: 34
Originally posted by Eric Pascarello:

If you want another html page, then the only way you can do it with JavaScript is if you are grabbing a page on the same domain and that your browser supports AJAX or iframes.

Eric


use a hidden iframe or something?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
var content = parent.iframeName.document.body.innerHTML;
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
var content = document.body.innerHTML;


Is innerHTML supported on all the major browsers these days? I think it used to be an IE invention.


Ping & DNS - updated with new look and Ping home screen widget
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Yes it is supported by all of the major browsers eventhough it is not part of the W3C spec. innerText is not supported by all the browsers.

Eric
Kevin Cornwell
Ranch Hand

Joined: Feb 01, 2005
Posts: 34
thanks for the help

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrive Web Page via Javascript
 
Similar Threads
Use an xml document which is dynamically created by Servlet/JSP
text field validations
Sessions and access from javascript?
Detect IP Address using JavaScript
Javascript NullPointerException???