zoukankan      html  css  js  c++  java
  • JS可以监控手机的返回键吗?

    html5的话

    一进页面就pushState,然后监控onpopstate
    不过好像没有办法知道是前进还是后退
    我的奇淫巧计是,一个数字变量,pushState一个锚,锚是这个数字,前进一个页面数字+1,重新pushState这个变量.....onpopstate的时候判断如果锚的值小于全局变量.说明后退了.. dosomething
     
    if (window.history && window.history.pushState) { $(window).on('popstate', function() { var hashLocation = location.hash; var hashSplit = hashLocation.split("#!/"); var hashName = hashSplit[1]; if (hashName !== '') { var hash = window.location.hash; if (hash === '') { alert('後退按鈕點擊'); } } }); window.history.pushState('forward', null, './#forward'); }



    作者:Cherry
    链接:https://www.zhihu.com/question/28223004/answer/148094159
    来源:知乎

    作者:万全
    链接:https://www.zhihu.com/question/28223004/answer/158235597
    来源:知乎
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    var _this = this; var open_i = 0; pushHistory(); window.addEventListener("popstate", function(e) { if (//t/n/.test(location.href)) { location.href='//ch1'; // location.replace('//m.k.sohu.com?backMain=page1'); }else{ WeixinJSBridge.invoke('closeWindow',{},function(res){ //alert(res.err_msg); }); } // } }, false); function pushHistory() { var state = { title: "首页", url: "/t/ch1?backMain=ch1" }; window.history.pushState(state, state.title, state.url); window.history.replaceState(state, state.title, state.url); }
  • 相关阅读:
    Soap1.1和Soap1.2的区别
    常用开源软件许可协议简介
    Web优化之Javascript Compressor
    Web优化之YaHoo Web优化的14条法则
    Installing Cygwin on Windows 7 And Configure SSH
    Different Between Cygwin And MinGw
    xml读取异常Invalid byte 1 of 1-byte UTF-8 sequence
    JAVA事务系列三:JTA事务
    JAVA事务系列二:JDBC事务
    帅才将才慧才
  • 原文地址:https://www.cnblogs.com/xzzzys/p/8422913.html
Copyright © 2011-2022 走看看