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


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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
Rancher

Joined: Mar 22, 2005
Posts: 42954
    
  73
var content = document.body.innerHTML;


Is innerHTML supported on all the major browsers these days? I think it used to be an IE invention.
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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Retrive Web Page via Javascript