i would like to create a JavaScript string that holds a dynamic php page
for the
newwindow=window.open();
newdocument=newwindow.document;
newdocument.write(HTMLstring);
newdocument.close();
functions.
when i try to insert the first part of the page it starts a php block
HTMLstring+='<?php';
HTMLstring+='echo "this should print";';
HTMLstring+='?>';
i have tried to start with
HTMLstring+='<\?php';
but i get
<!--?phpecho "this should print";?-->
is there a way to do this in JavaScript?
thank you
You are misunderstanding how JavaScript and PHP work. PHP runs on the server, JavaScript runs in the client. Using JavaScript to create PHP code is fundamentally impossible.
In your case, it should be possible to use PHP to output the string into JavaScript directly (like
the other common workaround for when you need to access PHP from within JavaScript is Ajax.