监听地址栏hash值的变化

2018-01-27 12:43:28

1  history.js//兼容ie6+

2  hashchange

$(window).on("hashchange", function() {//兼容ie8+和手机端
            $('.div1').append(This.location.hash);
        });

3 pushState//兼容ie9+

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

http://www.cnblogs.com/hustskyking/p/history-api-in-html5.html

$('.a').on('click', function() {// 创建新history实体
             history.pushState({a:'aa'}, '', location.href+'?'+Math.random());
             });
             $('.b').on('click', function() {// 修改新history实体(虽然浏览记录确实生成了2条,但是实际你只能找到被修改后的{a:'bb'})
             history.replaceState({a:'bb'}, '', location.href+'?'+Math.random()+'------');
             });
             window.addEventListener('popstate', function() {// 前进后退触发
                console.log(history);
                console.log(history.state);// 这里是你设置的{a:'aa'}
             });


  • 2019-10-27 11:02:10

    mac不要输入sudo,免密设置

    mac有时候使用终端进行操作,会让输入sudo 并且要输入命令,这要很啰嗦,浪费时间,我们得想办法去掉。

  • 2019-10-27 11:08:11

    Mac系统移到废纸篓的快捷键是什么

    用Windows键盘上的delete键和del键都不能删除文件,那么在Mac系统移到废纸篓的快捷键是什么?答:在移到废纸篓的快捷键组合就是Command + delete,可以将文件删除到废纸篓。清空废纸篓的快捷键是 Command + shift + delete​。

  • 2019-10-29 11:30:12

    Vue路由的$router.back(-1)回退时如何判断有没有上一个路由

    这个函数是这样的,判断当前页面的历史记录是不是小于等于1,如果小于等于1,说明这个页面没有可以返回的上一页,如果没有可以返回的上一页,就给地址栏加上一个goindex=true的参数,这样你从这个页面在往下一个页面跳转在返回,这个参数就一直加上的