頁面跳轉后,瀏覽器地址欄地址保持不變


有兩個方法,一個使用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM