我正在使用hashchange事件来询问一个确认对话框,说如果移动当前页面中的数据将会丢失。
我已经这样实现了:
window.onhashchange = function() {
if(window.confirm("Do you really want to close?")){
}
};
此事件已正确触发。但是,如果用户单击“是”,则页面不会更改。 {...}我需要什么?
答案 0 :(得分:0)
请尝试
window.onhashchange = function() {
if (window.confirm("Do you really want to navigate?")) {
location.hash = location.hash; // or set the hash elsewhere and change here
}
};