Javascript 确认导航不工作

Javascript 确认导航不工作,javascript,Javascript,我见过这种用法,但它对我不起作用 var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) return "You have attempted to leave this page. If you have made any changes to the fields without clicking the

我见过这种用法,但它对我不起作用

 var needToConfirm = true;

window.onbeforeunload = confirmExit;
function confirmExit() {
    if (needToConfirm)
        return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
}

我能够让它在IE和FF中与jQuery一起工作:

$(window).bind('beforeunload', function(){

});

代码在我们的系统中运行良好,您是否检查了localyes@ChakravarthySM我是否遗漏了什么??完整的代码?它正在工作,您希望它如何工作?它不在本地工作的原因是什么@Chakravarthysm您是否在脚本标记中包含了该文件或从单独的js文件调用该文件,如果是,您是否在html文件中调用该文件