Click to See Complete Forum and Search --> : otaining html text using JavaScript
dwynglng
04-02-2003, 01:16 PM
Is there a way to obtain the HTML text of the current page using JavaScript?
For example if view source gives:
<html> <body> Hello World </body> </html>
Then I'm looking for a way to put the above html in a JavaScript variable.
Thanks
Wayne
BestZest
04-02-2003, 01:37 PM
Hey, I asked this a few weeks ago! :p Ok, give the body tag an 'id' ie: <body id="page">
you can then get the document html by calling:
document.getElementById("page").innerHTML
and put this in a varible by putting:
pageHTML=document.getElementById("page").innerHTML
Thanks to khalidali63 who taught me this at http://forums.webdeveloper.com/showthread.php?s=&threadid=3759
BestZest
neenerbean
04-02-2003, 04:26 PM
can you post an example of what you guys are talking about? is this like inserting a page within a page? cause i've been dying to figure out how to do that!!
lemme know...
::ames::
BestZest
04-03-2003, 10:17 AM
Ok. You new to JavaScript by any chance?
1. To put a page in a page use the '<iframe></iframe>' tags. Within these you can specify the source eg. 'src="page2.html" ' and the width and height.
2. Here is the actual code to grab the source code to the current page:
<HTML>
<HEAD>
<TITLE>Grab source</TITLE>
<SCRIPT LANGUAGE='JavaScript'>
function grabSource() {
html=document.getElementById("page").innerHTML
}
</SCRIPT>
</HEAD>
<BODY id="page">
This is the content
</BODY>
</HTML>
In this case, when you call 'grabSource()', the 'html' varible would contain '<i>This is the content</i>'. The important bits are in bold.
Hope this helps,
BestZest
neenerbean
04-03-2003, 11:44 AM
Originally posted by BestZest
Ok. You new to JavaScript by any chance?
yah, how'd you guess? ;)
and thanks for your help!
Vladdy
04-03-2003, 11:46 AM
Originally posted by neenerbean
...inserting a page within a page? cause i've been dying to figure out how to do that!!
You may find this (http://forums.webdeveloper.com/showthread.php?s=&threadid=6810) interesting...