onbeforeunload event is not working when user not click inside the body of page

I want call one function when user open any page and without click on that page, he just close the page.

I have tried this to put one button and click on that button using coding after page loading is complete , but it is not working.

I am follow this link. W3School

In this link , when you not click in result portion and reload page then it will not display alert , but when you click result portion and reload page then it will displaying a alert.

This is because the onbeforeunload is attached to the <iframe>'s window object, and when you do unload the main page, this event won't fire unless you had focus on this iframe.

Same will happen with StackSnippet here:

onbeforeunload = e => true;
<span>click to toggle iframe's focus</span>
 Run code snippetHide results

最新文章

  1. Android注解使用之ButterKnife 8.0注解使用介绍
  2. 怎么样在Myeclipse中配置JDK?
  3. 慕课网-Java入门第一季-6-8 使用 foreach 操作数组
  4. 再来一发!DB2 应用程序如何从数据库取数据 Fetch
  5. JQuery之正则表达式
  6. URAL 1936 Roshambo 题解
  7. lintcode :Trailing Zeros 尾部的零
  8. (转)原子操作 Interlocked系列函数
  9. (转)让浏览器支持Webp
  10. Fiddler屏蔽某些url的抓取方法
  11. 将简单的lambda表达式树转为对应的sqlwhere条件
  12. 为什么要使用Docker?
  13. JSON 序列化的时候忽略无效的属性值
  14. 南邮攻防训练平台逆向第四题WxyVM
  15. 函数纹理(国际象棋棋盘纹理&amp;粗布纹理)MFC
  16. MAC机下用Terminal操作MySql
  17. CCO2017 Vera and Trail Building 构造+图论
  18. CANopen和DeviceNet有何异同
  19. mac 类似Xshell
  20. email 校验

热门文章

  1. 如何创作用纯 CSS 绘制一支栩栩如生的铅笔
  2. Mac OS X下安装Vue脚手架(vue-cli)
  3. python面向对象(反射)(四)
  4. MPEG-4与H.264的区别 , 编码 以及 应用
  5. PAT Basic 1052
  6. 2. vsCode 安装GoCode
  7. python 四——线程、进程、协程
  8. spring常用的注解
  9. Cookie窃取实验
  10. 安装oracle提示swap交换分区太小