PHP and Javascript interaction Methods

Source: Internet
Author: User

How to make the front-end page and
Maintaining interaction between CGI pages in the background is always a problem. Here we will introduce two
.

Method 1: use cookies for interaction. There are three files in total:
Index.htm,action.php, main.htm
It turns out that the front page main.htm and the background action. php use the page framework
Index.htm is organized to set the page width of action. php to 0.
Impact display. Action.php puts the information into cookie, and main.htm reads the information
Cookie. In main.htm, you can also re-read action. php
To control the CGI program in the background.

Index.htm
---------------------------------------------------------------
<Html>
<Head>
<Title> Test </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>

<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> This page uses the page framework, but your browser does not support it. </P>
</Body>
</Noframes>
</Html>
---------------------------------------------------------------

Action. php
---------------------------------------------------------------
<?
Srand (double) microtime () * 1000000 );
$ Result = revert (0,100 );
Setcookie ("action", $ result, time () + 900 ,"/");
?>
---------------------------------------------------------------

Main.htm
---------------------------------------------------------------
<Html>
<Head>
<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>
</Head>
<Body bgcolor = "# FFFFFF">
<Form name = "test">
The current parameter is <input type = "text" name = "current_cookie" size = "80" maxlength = "1000">
</Form>
<Script language = "javascript">
SetInterval ("get_cookie ()", 200 );
</Script>
<Br>
<A href = "action. php" target = "leftFrame"> re-read Cookie </a>
</Body>
</Html>
---------------------------------------------------------------

Method 2: directly implement interaction through parent. There are three files in total:
Index.htm,action.php, main.htm,index.htm is the same as the previous one.
The principle is to directly pass through parent. rightFrame. test. current_cookie.value.
Information.

Action. php
---------------------------------------------------------------
<?
Srand (double) microtime () * 1000000 );
$ Result = revert (0,100 );
?>
<Script language = "javascript">
Parent. rightFrame. test. current_cookie.value = "<? Echo $ result?> ";
</Script>
---------------------------------------------------------------

Main.htm
---------------------------------------------------------------
<Html>
<Head>
<Title> Test </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body bgcolor = "# FFFFFF">
<Form name = "test">
The current parameter is <input type = "text" name = "current_cookie" size = "80" maxlength = "1000">
</Form>
<Br>
<A href = "action. php" target = "leftFrame"> re-read Cookie </a>
</Body>
</Html>
---------------------------------------------------------------

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.