history.pushState的用处

以前做后台管理的时候,采用的是ajax+iframe,导致的问题是“刷新”就会回到首页,采用html5的history.pushState可以更好的完成,项目pajx就是封装了history和ajax的功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello</title>
</head>
<body>
    <button id="btn">click</button>

    <a id="a" href="http://www.baidu.com" target="_self">baidu</a>

    <script>
        document.getElementById('btn').onclick = function() {
            var title = '新的页面'
            history.pushState(null, null, "line.html");

            document.title = title

            return false;
        }

        document.getElementById('a').onclick =  function () {
            console.log('...jump')

            // 可以阻止链接跳转
            return false
        }
    </script>
</body>
</html>

https://www.zhangxinxu.com/wordpress/2013/06/html5-history-api-pushstate-replacestate-ajax/