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); }
  • 相关阅读:
    sql 自定义函数-16进制转10进制
    编写一个单独的Web Service for Delphi
    Web Service
    无需WEB服务器的WEBServices
    Svn总是提示输入账号密码
    阿里云服务器SQLSERVER 2019 远程服务器环境搭建
    svn客户端使用
    数据库设计规则(重新整理)
    数据库表字段命名规范
    怎样去掉DELPHI 10.3.3 启动后的 security alert 提示窗体
  • 原文地址:https://www.cnblogs.com/xzzzys/p/8422913.html
Copyright © 2011-2022 走看看