Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Html source of a page into a variable, please help

Status
Not open for further replies.

SuperCyber

Programmer
Aug 10, 2001
35
US
I need to figure out a way to take a page that varies in length each time and read the html code and place it into a variable so the page that i forward to can request the data. Any help is greatly appreciated.

Thanks,
Brian
 
Hi SuperCyber,

Maybe this can help:

You should put this code in the page you wish to read on:
<html>
<head>
<title>Page to read</title>
<script language=&quot;javascript&quot;>
function readHTML()
{
pagecontent=mypage.innerHTML;
alert(pagecontent);
}
</script>
</head>
<body id=&quot;mypage&quot; onload=&quot;readHTML()&quot;>

All of the HTML code goes here


</body>
</html>

The variable I named 'pagecontent'(you name it what you want) will store all of the HTML code between <body> and the closing tag </body> not including the <body></body> tags themselves.
If you need all the HTML code including <body></body> you
should use:

pagecontent=mypage.outerHTML;

I used alert to show the code.Obviously this must be removed.It's just for example.
Once the HTML is stored in the variable,you can process it the way you wish.


I don't know another way to solve the problem.I hope this helps you.


Best Regards

alexfusion



 
Thank you for your response. Sorry, I should of said that I need the HTML code, tags included, at the submitting of the page. So at the end of the site when the user clicks on the submit button, I want to put all of the body html code into a variable so I can reference it on the page it will be submitted to. Hope this make my problem more clear.

Thank you,
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top