zoukankan      html  css  js  c++  java
  • 页面跳转后,浏览器地址栏地址保持不变(转载)

    转载至:https://www.cnblogs.com/5202m/archive/2012/09/20/2694879.html

    有两个方法,一个使用JS实现,一个是用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="http://www.5202m.com" mce_src="http://www.baidu.com">
    
    </iframe>

    缺点是,存在跨域访问的问题。

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

    转载至http://blog.sina.com.cn/s/blog_74f702e601013t0i.html

  • 相关阅读:
    二叉查找树
    Hash算法原理理解
    算法的时间复杂度
    解决Ubuntu14.04下Clementine音乐播放器不能播放wma文件的问题
    Ubuntu 14.04 开启启动器图标最小化功能
    Ubuntu14.04建立WiFi热点
    C语言运算符优先级
    老鸟的Python入门教程
    MD5算法步骤详解
    MD5算法
  • 原文地址:https://www.cnblogs.com/lst619247/p/9197051.html
Copyright © 2011-2022 走看看