- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在选项卡关闭时显示“onbeforeunload
警报”,但是当我填写表单然后关闭选项卡时,“onbeforeunload
警报”不会出现。
如何更改代码,以便在填写表单时显示“onbeforeunload
警报”?这是我使用的代码:
window.onbeforeunload = confirmExit;
function confirmExit() {
return "You are about to exit the system before freezing your declaration! If you leave now and never return to freeze your declaration; then they will not go into effect and you may lose tax deduction, Are you sure you want to leave now?";
}
$(function() {
$("a").click(function() {
window.onbeforeunload = null;
});
$("input").click(function() {
window.onbeforeunload = null;
});
});
最佳答案
How can I change the code so "
unbeforeunload
alert" can show when the form is filled?
您实际上点击的是<input />
通过填写表格吗?因此,一旦您单击 <input />
,unbeforeunload
设置为 null
(删除警报)通过以下代码:
$("input").click(function() {
window.onbeforeunload = null;
});
请删除该代码,然后就一切就绪了。 :)
或者您可以定位提交按钮,更具体地说:
$("input").click(function() {
window.onbeforeunload = null;
});
$("input[type='submit']").click(function() {
window.onbeforeunload = confirmExit;
});
关于javascript - 如何在填写表单时显示 onbeforeunload 警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625529/
这是我用于window.onbeforeunload的代码 window.onbeforeunload = func; function func() {
我对我的申请有疑问。每当用户意外关闭浏览器窗口时,我想在此之前执行一些清理操作。我已经使用了 onunload 事件,但问题是该事件有时会触发,有时不会。我该怎么办,有没有更好的方法来处理此类问题。
这是我用于window.onbeforeunload的代码 window.onbeforeunload = func; function func() {
我正在尝试开发一个带有单独设置窗口( Electron )的应用程序。当设置窗口打开而主窗口关闭时,我想防止主窗口关闭并聚焦设置窗口。 现在我这样做如下: window.onbeforeunload
我对 JavaScript 还很陌生。我有一个简单的 onbeforeunload 函数,当前适用于所有页面,我希望它为某些子页面(#clients、#products、#news)激活,但不适用于我
我正在使用以下代码。但由于事件未定义,我得到了结果。造成这种情况的可能原因是什么? window.onbeforeunload = function(event){ if(window.e
我想要实现的是,如果用户尝试关闭页面或在不先保存的情况下导航离开页面,则警告用户未保存的更改。 我已经设法弹出 OnBeforeUnload() 对话框...但如果用户没有修改任何字段值,我根本不希望
我有一个 onbeforeunload 事件,该事件应该在用户访问新页面时触发。它工作得很好,但我发现每当用户从他们所在的页面下载文件时,它也会在 Chrome 中触发。 我希望能够判断该事件是否因为
我想检查当前浏览器是否支持 onbeforeunload 事件。常见的 javascript 方法似乎不起作用: if (window.onbeforeunload) { alert('yes
我现在有这个小脚本,用于检查表单上是否进行了任何更改。如果有变化然后我将标志设置为“Y”。我在 body 标记中的 onBeforeunload="changeConfirm()"位置调用此函数。我知
在 MVC 应用程序中离开页面之前,我使用以下 JS 进行确认。 window.onbeforeunload = function() { return 'Any Unsaved data w
这是一个最小的例子 - index.php hi there var id = ""; script.js $(document).read
我有这个代码: (function() { window.onbeforeunload = function () { alert("hi") co
我使用这个片段已经快两年了。那时还好,直到我看到它今天在 Google Chrome 版本 51.0.2704.103m 上无法正常工作。 $(window).on('beforeunload', f
2007 年,在一篇名为“Mastering The Back Button With Javascript”的帖子中,Patrick Hunlock 声称只包含一个 onbeforeunload页面
我们有一些用户填写的表格。如果在此过程中导航离开,我需要执行操作。 我发现了许多在浏览器中组合 onbeforeunload 和 unload 的示例,以提示用户并提醒他们,如果他们关闭或导航离开信息
如何禁用链接的 onbeforeunload? var show = true; function showWindow(){ if(show){ alert('Hi
我正在通过以下代码跟踪窗口关闭/导航事件。 window.onbeforeunload = winClose; function winClose() { if (isData
我有 Uber-Upload! 我想做的是,如果你按下那个按钮,它也会设置一个变量,这样如果你试图离开页面,它会弹出其中一个“你确定要离开吗此页面”警报,以防止人们在上传过程中意外离开。 不要担
我想在用户离开网站时更新数据库。我正在为我的网站使用 php。我正在使用 javascript 函数 onbeforeunload 并通过 ajax 调用 php 来更新数据库。 现在的问题是 Ope
我是一名优秀的程序员,十分优秀!