Forum Moderators: coopster
I'm trying to convert one of my scripts from JavaScript to PHP to make it more accessible.
Most of it is if/else commands, which I've already been able to successfully convert. However, I have a few lines I'm having trouble converting.
Any suggestions? Thanks.
<script language="JavaScript">
var parentwin = external.menuArguments;
var doc = parentwin.document;
var sel = doc.selection;
var rng = sel.createRange();
var strhtml = new String(rng.htmlText);
alert(strhtml);
</script>
If you might describe what this snippet of your code is doing we should be able to offer insight as to how to approach a solution ...
PHP has no way of knowing what is happening at the client unless information is sent back to the server for it to digest.
Similarly, PHP has no handlers for the 'document' or 'window' object models. The 'window' is a reference to the client's browser window and the 'document' is a reference to the compiled file that is loaded into the client window, neither of which are available for PHP to deal with once the 'document' leaves the server.
Lastly, there is no PHP analogy to the Javascript alert() function, which is a client-side function.
Bummage ... ;)
echo "<script language=\"JavaScript\">\n";
echo "var parentwin = external.menuArguments;\n";
echo "var doc = parentwin.document;\n";
echo "var sel = doc.selection;\n";
echo "var rng = sel.createRange();\n";
echo "var strhtml = new String(rng.htmlText);\n";
echo "alert(strhtml);\n";
echo "</script>\n";