现在的位置: 首页 > 综合 > 正文

JQuery – 点击浏览器后退键时发出警告

2013年12月07日 ⁄ 综合 ⁄ 共 949字 ⁄ 字号 评论关闭

jQuery(document).ready(function ($) {
                    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("Back button isn't supported. You are leaving this application on next clicking the back button");
                                }
                            }
                        });
                        window.history.pushState('forward'null'./#forward');
                    }
                });

参考:http://stackoverflow.com/questions/6359327/detect-back-button-click-in-browser

抱歉!评论已关闭.