PHP与Javascript的两种交互方式
时间:2008-05-29 来源:剑心通明
.Hsh133 { display:none; }
在网页制作过程中怎样在不刷新页面的情况下使前台页面和
后台CGI页面保持交互一直是个问题。这里介绍两个我在实践中使
用的方法。
方法一:通过Cookie交互。一共是三个文件,分别为:
index.htm,action.php,main.htm
原理为前台页面main.htm和后台action.php通过页面框架
index.htm组织起来,将action.php的页面宽度设为0,这样并不
影响显示。action.php将信息放入cookie中,main.htm通过读取
cookie来实现交互。在main.htm中也可以通过重新读取action.php
来实现控制后台CGI程序。
index.htm
---------------------------------------------------------------
以下为引用的内容:
www.phperz.com
Test
本页使用页面框架,但是您的浏览器不支持。
---------------------------------------------------------------
action.php
---------------------------------------------------------------
以下为引用的内容:
phperz.com
---------------------------------------------------------------
main.htm
---------------------------------------------------------------
以下为引用的内容:
Test
phperz.com
function get_cookie()
{
document.test.current_cookie.value=document.cookie;
}
当前参数为
setInterval("get_cookie()",200);
重新读取Cookie
---------------------------------------------------------------
方法二:直接通过parent.*.*来实现交互。一共是三个文件,分别为:
index.htm,action.php,main.htm,其中index.htm和前面的一样。
原理为通过parent.rightFrame.test.current_cookie.value直接传递信息。
phperz.com
action.php
---------------------------------------------------------------
以下为引用的内容:
parent.rightFrame.test.current_cookie.value="";
---------------------------------------------------------------
main.htm
---------------------------------------------------------------
以下为引用的内容:
php程序员站
Test
当前参数为
重新读取Cookie
相关阅读 更多 +