离开网页时发出警报

发布于 2024-08-01 14:51:03 字数 323 浏览 3 评论 0原文

当我尝试关闭包含未保存更改的 Google 文档选项卡时,这就是我在浏览器 (FF 3.5) 中看到的内容。

您确定要离开吗 从这个页面?

您对此有未保存的更改 文档。 单击立即取消,然后 ‘拯救’来拯救他们。 单击“立即确定”即可 丢弃它们。

按“确定”继续,或按“取消” 停留在当前页面。

我的问题是,此类警报是否是网络应用程序的一部分(例如 gdocs),还是由浏览器发出? 如果是后者,这是如何完成的?

When I try to close my Google docs tab with unsaved changes, this is what I get in my browser (FF 3.5).

Are you sure you want to navigate away
from this page?

You have unsaved changes in this
document. Click Cancel now, then
'Save' to save them. Click OK now to
discard them.

Press OK to continue, or Cancel to
stay on the current page.

My question is whether such alerts are part of the web app (gdocs for eg.) or are they given out by the browser? If latter, how is this done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏九 2024-08-08 14:51:03

通过浏览器。 这是 beforeunload 事件处理程序返回对话框的自定义文本,这只是三个段落的中间 - 其他两个段落以及按钮的文本无法自定义或以其他方式更改。

window.onbeforeunload = function(){ return 'Testing...' }

// OR

var unloadListener = function(){ return 'Testing...' };
window.addEventListener('beforeunload', unloadListener);

将产生一个对话框,显示

Are you sure you want to navigate away from this page?

Testing...

Press OK to continue, or Cancel to stay on the current page.

您可以通过将处理程序设置为 null 来取消此设置

window.onbeforeunload = null;

// OR

window.removeEventListener('beforeunload', unloadListener);

By the browser. It's the beforeunload event handler that returns the customized text of the dialog, which is only the middle of the three paragraphs - the other two paragraphs as well as the text of the buttons cannot be customized or otherwise changed.

window.onbeforeunload = function(){ return 'Testing...' }

// OR

var unloadListener = function(){ return 'Testing...' };
window.addEventListener('beforeunload', unloadListener);

Will yield a dialog that says

Are you sure you want to navigate away from this page?

Testing...

Press OK to continue, or Cancel to stay on the current page.

You can nullify this by setting the handler to null

window.onbeforeunload = null;

// OR

window.removeEventListener('beforeunload', unloadListener);
素年丶 2024-08-08 14:51:03

警报是 Web 应用程序的一部分。 查看源代码并查看javascript。

The alerts are part of the web application. View the source code and look at the javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文