Html5無刷新修改browser Url的方法

字號:


    Ajax局部刷新可以通過HTML5的新特性修改browser address,下面為大家介紹下具體的實現(xiàn),希望對大家有所幫助
    window.history表示window對象的歷史記錄
    window.history.pushState(object, title, new_url) -- 在window.history里新增一個歷史記錄點
    window.history.replaceState(object, title, new_url) -- 在window.history替換當前page的歷史記錄點
    object - 可以擴展想要的object
    title - 目前所有瀏覽器都不支持
    new_url 瀏覽器不會檢查url是否存在,只改變url,url必須同域,不能跨域
    eg: original url: www.test.com
    window.history.pushState({time: 'test'}, ' ', 'www.test_test.com')