*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 41088
    
  43
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 - my free Android networking tools app
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
Detect IP Address using JavaScript
Sessions and access from javascript?
Use an xml document which is dynamically created by Servlet/JSP
Javascript NullPointerException???
text field validations