zoukankan      html  css  js  c++  java
  • JS监听H5返回

    js监听手机返回键,回到指定界面

    方法一、

    $(function(){

    pushHistory();

    window.addEventListener("popstate", function(e) {

    window.location = 返回的地址

    }, false);

    function pushHistory() {

    var state = {

    title: "title",

    url: "#"

    };

    window.history.pushState(state, "title", "#");

    }

    });

     

    方法二、JS监听手机的物理返回键

    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');

    }

    方法三、JavaScript监听手机物理返回键

    pushHistory();

    window.addEventListener("popstate", function(e) {

    window.location = 'http://www.baidu.com';

    }, false);

    function pushHistory() {

    var state = {

    title: "title",

    url: "#"

    };

    window.history.pushState(state, "title", "#");

    }

    摘录网络:

    文章来源:刘俊涛的博客 欢迎关注公众号、留言、评论,一起学习。

    __________________________________________________________________________________

    若有帮助到您,欢迎点击推荐,您的支持是对我坚持最好的肯定(*^_^*)

    耶和华是我的牧者,我必不至缺乏。
  • 相关阅读:
    C# 语言基础(++和--运算)
    Android RSA加密解密
    laravel redis
    larave5.1l队列
    shell更改目录编码
    Linux的权限说明
    MySQL主从架构之Master-Master互为主备
    php curl流方式远程下载大文件
    php session 跨页失效问题
    mysql中文字段转拼音首字母,以及中文拼音模糊查询
  • 原文地址:https://www.cnblogs.com/lovebing/p/14722985.html
Copyright © 2011-2022 走看看