Forum Moderators: mack

Message Too Old, No Replies

Inserting Javascript into php

         

easypeasy

11:00 pm on Apr 14, 2006 (gmt 0)



I have the following php file in frontpage. Please could someone tell me how i need to edit it to get the javascript running. I know i need to add <? and echo" somewhere but i'm very new to this and don't know where it goes.Please help.

<html>

<head>
<script language="JavaScript">
<!--
function autoResize(id){
var newheight;
var newwidth;

if(document.getElementById){
newheight=document.getElementById(id).contentWindo w.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow .document .body.scrollWidth;
}

document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">

<title>Home</title>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="none">
<meta name="Microsoft Border" content="tlb, default">
</head>
<?php

//Get Page variable
$page = $_GET['page'];

//If no page is specified
if(!$page ) {

$page = "http://www.google.com";

}

//Then add the $framelocation variable to the irframe tag
?>

<body><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>


<p>
<a href="index.htm"><img src="_derived/home_cmp_Arctic000_gbtn.gif" width="90" height="25" border="0" alt="Home" align="middle"></a> <img src="_derived/index.php_cmp_Arctic000_gbtn.gif" width="90" height="25" border="0" alt="Home" align="middle"> <a href="feedback.htm"><img src="_derived/feedback.htm_cmp_Arctic000_gbtn.gif" width="90" height="25" border="0" alt="Feedback" align="middle"></a> <a href="toc.htm"><img src="_derived/toc.htm_cmp_Arctic000_gbtn.gif" width="90" height="25" border="0" alt="Contents" align="middle"></a> <a href="search.htm"><img src="_derived/search.htm_cmp_Arctic000_gbtn.gif" width="90" height="25" border="0" alt="Search" align="middle"></a>
</p>
<p><img border="0" src="_borders/bllogo0.gif" width="521" height="97"><br>

</p>

</td></tr><!--msnavigation--></table><!--msnavigation--><table dir="ltr" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top" width="1%">

<p>

</p>

</td><td valign="top" width="24"></td><!--msnavigation--><td valign="top">
<IFRAME SRC="<?php echo $page?>" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"?>%2522" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"?>%22" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"?>" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"></iframe>
<!--msnavigation--></td></tr><!--msnavigation--></table><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>

<p>&nbsp;</p>
<h5>Send mail to <a href="email address">
email address</a> with
questions or comments about this web site.<br>
Copyright<br>
</h5>

</td></tr><!--msnavigation--></table></body>

</html>

ogletree

3:13 am on Apr 16, 2006 (gmt 0)

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



I'm not an expert nor do I want to try and figure out what you are doing there but I did want to say that javascript and php can not interact with each other. The PHP will be completely done before the javascript begins. PHP happens at the server before the page is loaded and javascript happens after the page is loaded.

If I completely missed the point I'm sorry. Like I said I am no expert. I just saw an unanswered thread and thought I would try to help.

httpwebwitch

3:36 am on Apr 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you're right. PHP will execute at the server. The output from PHP is what gets sent to the browser; it is what we call "server-side" scripting.

Then you have stuff that arrives at the browser; that will include HTML, CSS, and JavaScript. Javascript runs on the client's machine; we call it "client-side" scripting.

But indeed PHP and Javascript are highly compatible. you can use PHP to write javascript. the technique is very useful when you have complex client-side scripts that use srver-generated data.

That's all a preamble to actually solving your problem. I see some weird things going on here:

<IFRAME SRC="<?php echo $page?>" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"?>%2522" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"?>%22" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"?>"

I think what you want is:

<IFRAME SRC="<?php echo $page?>" width="100%" height="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');">