javascript - 当用户离开我的 Javascript/AngularJS 网站时,如何提示模式?

标签 javascript angularjs events dom-events onbeforeunload

AngularJS 或 Javascript 有没有办法检测用户正在离开我的网站(可以关闭浏览器或进入另一个页面)并提示模式? 在此模式中,我想询问用户为什么要离开。

还有,有这样的东西可以吗?我的网站会因为这个“烦人的功能”而被列入黑名单吗?

最佳答案

为了对抗不需要的弹出窗口,现代浏览器严格限制 JavaScript 在页面卸载之前可以执行的操作。

来自文档:

Window: beforeunload event

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.

This event enables a web page to trigger a confirmation dialog asking the user if they really want to leave the page. If the user confirms, the browser navigates to the new page, otherwise it cancels the navigation.

欲了解更多信息,请参阅

关于javascript - 当用户离开我的 Javascript/AngularJS 网站时,如何提示模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34913255/

相关文章:

javascript - 通过 Vue.js 中的嵌套组件传递数据

php - 如何防止 Curl 重定向

javascript - ui-select 将数组元素显示为下拉列表中的选项

javascript - 用js更改字符代码并显示新字符

C# 和 Moq - 如何断言未引发事件

javascript - 将网络请求从同步转换为异步(PHP/Javascript)

javascript - 在滚动更改菜单 HTML 的颜色

javascript - Angular : attach $viewContentLoaded to manually bootstraped app

javascript - 延迟表单提交(AngularJS)

MySql 安排事件