Forum Moderators: coopster

Message Too Old, No Replies

How do you get JavaScript's document.body.innerHTML to PHP

         

jd80

12:43 pm on Jan 27, 2004 (gmt 0)

10+ Year Member



Is it possible to pass JavaScript's document.body.innerHTML to PHP and then be manipulated using PHP code?

isitreal

7:40 pm on Jan 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I understand PHP correctly, no there isn't, that's because all the PHP on your page is executed before it is sent to the client browser, while all the javascript on your page is not executed until the page is run on the client browser.

The only way around that would be to put a cookie containing the javascript value, but PHP can't write to most browser features like Javascript can. You could have the page reload after the javascript has executed, create the cookie, then rewrite the page using the cookie value with PHP, using that to send javascript back the new value, but that would be a real pain for little gain, and lots of debugging problems.

If anyone else knows of way to do this better though I'd be interested to hear it.

ORBiTrus

7:27 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



Hmmm.... like this?

<script language='JavaScript'>
function setFormContents(theForm) {
theForm.html.value=document.body.innerHTML;
return true;
}
</script>

<form action='...' method='post' onSubmit='setFormContents(this)'>

<input type='hidden' name='html' value='' />
<input type='submit' value='Send this page to PHP' />

</form>

Likewise, you could it by a link's GET if you append, but that would exceed the char limit... So it has to be by POST using this method...