PHP background program and JavaScript Two Interactive ways _php skills

Source: Internet
Author: User
Tags rand
Method One: Interact with cookies.
A total of three files, respectively: index.htm,action.php,main.htm
Principle for the foreground page main.htm and background action.php through the page frame index.htm organized, the action.php page width set to 0, this does not affect the display. Action.php the information into a cookie and main.htm the interaction by reading the cookie. In Main.htm, you can also control the background CGI program by re-read the action.php.
Index.htm
Copy Code code as follows:

<title>Test</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<frameset framespacing= "0" border= "false" frameborder= "0" cols= "0,*" >
<frame name= "Leftframe" scrolling= "no" noresize src= "action.php" >
<frame name= "Rightframe" scrolling= "Auto" src= "main.htm" >
</frameset><noframes>
<body bgcolor= "#FFFFFF" >
<p> page frames are used on this page, but your browser is not supported. </p>
</body>
</noframes>

action.php
Copy Code code as follows:

<?php
Srand (Double) microtime () *1000000);
$result =rand (0,100);
Setcookie ("Action", $result, Time () +900, "/");
?>

Main.htm
Copy Code code as follows:

<title>Test</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "JavaScript" >
function Get_cookie ()
{
Document.test.current_cookie.value=document.cookie;
}
</script>
<body bgcolor= "#FFFFFF" >
<form name= "Test" >
The current parameter is <input type= "text" name= "Current_cookie" size= "M" maxlength= "1000" >
</form>
<script language= "JavaScript" >
SetInterval ("Get_cookie ()", 200);
</script>
<br>
<a href= "action.php" target= "Leftframe" > re-read cookie</a>
</body>

Method Two: Directly through Parent.*.* to realize the interaction.
A total of three files, respectively: Index.htm,action.php,main.htm, where index.htm and the same as before.
The principle is to transmit information directly through Parent.rightFrame.test.current_cookie.value.
action.php
Copy Code code as follows:

?
Srand (Double) microtime () *1000000);
$result =rand (0,100);
?>
<script language= "JavaScript" >
Parent.rightframe.test.current_cookie.value= ". echo $result?> ";
</script>

Main.htm
Copy Code code as follows:

<title>Test</title>
& L T;meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor=" #FFFFFF ">
<form name=" Test >
Current parameter is &L T;input type= "text" name= "Current_cookie" size= "no" maxlength= "1000" >
</form>
<br>
<a href= "action.php" target= "Leftframe" > re-read cookie</a>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.