h5弹窗时 点击手机物理返回键 关闭弹窗 不跳页面

        function pushHistory() {
            var state = {
                title: "title",
                url: "#"
            };
            window.history.pushState(state, "title", "#");
        }


    
            window.addEventListener("popstate", function(e) {
                if ($("#agreementContent").css('display') == "block"){
                    $("#agreementContent").hide();
	            } else {
		        history.back()
	            }
            }, false);

弹窗显示时调用pushHistory()方法  ,  文档就绪事件中监听 popstate 如果弹窗正在显示就关闭弹窗,  如果不是就返回上一页面

猜你喜欢

转载自blog.csdn.net/qq_40095973/article/details/82663668
今日推荐