943,709 Members | Top Members by Rank

Ad:
Jun 12th, 2008
0

the innerHTML of page

Expand Post »
I'm trying to get some HTML code from a page. The only way to do this that I know of is
javascript Syntax (Toggle Plain Text)
  1. document.getElementById('id').innerHTML = 'newhtml';
But the problem is that the page is taken from the web and it has no IDs to get and I can't modify it by putting IDs.
So is there a way to get the innerHTML of the whole page so I can search for certain strings afterwards?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
SirDorius is offline Offline
10 posts
since Jun 2008
Jun 12th, 2008
0

Re: the innerHTML of page

Hi, SirDorius.

Instead of using
javascript Syntax (Toggle Plain Text)
  1. document.getElementById(id).innerHTML;
You could use
javascript Syntax (Toggle Plain Text)
  1. document.getElementsByTagName(tag)[0].innerHTML;

This method will give you an array of all the elements on the page with that tag name. Just access each tag like you would access an array.

For example, if you wanted to get the inner HTML of the third division on the page you could use:
javascript Syntax (Toggle Plain Text)
  1. document.getElementsByTagName("div")[2].innerHTML;

Hope that helps,

Adam
Reputation Points: 10
Solved Threads: 1
Newbie Poster
drago865 is offline Offline
14 posts
since Jan 2006
Jun 12th, 2008
0

Re: the innerHTML of page

Thanks Adam, that did help a lot!

Cheers!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
SirDorius is offline Offline
10 posts
since Jun 2008
Jun 13th, 2008
0

Re: the innerHTML of page

the inner html of the whole html document is
document.childNodes[1].innerHTML

or
document.body.innerHTML
if you just want the bodys html
Last edited by plazmo; Jun 13th, 2008 at 4:55 pm.
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Jun 13th, 2008
0

Re: the innerHTML of page

Thanks, document.body.innerHTML should be useful too
Reputation Points: 10
Solved Threads: 1
Newbie Poster
SirDorius is offline Offline
10 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: timescript- page redirection
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Reload parent page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC