首页 > 编程 > PHP > 正文

php跳转不改变浏览器地址

2020-03-22 17:08:08
字体:
来源:转载
供稿:网友

php跳转不改变浏览器地址有两个方法

1、使用JS实现

2、使用iframe实现

首先是JS实现,代码:

function createXMLHttpRequest(){    if(window.XMLHttpRequest){        XMLHttpR = new XMLHttpRequest();    }else if(window.ActiveXObject){        try{            XMLHttpR = new ActiveXObject("Msxml2.XMLHTTP");        }catch(e){            try{                XMLHttpR = new ActiveXObject("Microsoft.XMLHTTP");            }catch(e){            }        }    }}function sendRequest(url){    createXMLHttpRequest();    XMLHttpR.open("GET",url,true);    XMLHttpR.setRequestHeader("Content-Type","text/html;charset=utf-8");    XMLHttpR.onreadystatechange = processResponse;    XMLHttpR.send(null);}function processResponse(){    if(XMLHttpR.readyState ==4 && XMLHttpR.status == 200){        document.write(XMLHttpR.responseText);    }}

上面的代码就是实现页面跳转后,浏览器地址栏地址保持不变的方法。

方法二:使用iframe框架

<iframe id="frame3d" name="frame3d" frameborder="0" width="100%" scrolling="auto" style="margin-top: -4px;" onload="this.style.height=document.body.clientHeight-84" height="100%" src="https://www.5202m.com" mce_src="https://www.baidu.com"></iframe>

缺点:

存在跨域访问的问题。

总结:

推荐后台使用,前台对搜索引擎不友好,不利于优化。

推荐教程:PHP视频教程

以上就是php跳转不改变浏览器地址的详细内容,更多请关注 其它相关文章!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表