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

chrome 的onbeforeunload事件没有触发的更多相关文章

  1. 各浏览器对 onbeforeunload 事件的支持与触发条件实现有差异

    转载:http://www.w3help.org/zh-cn/causes/BX2047 标准参考 无. 问题描述 一般情况下,onbeforeunload 事件处理函数内会写入一些提示性语句,当用户 ...

  2. onunload事件和onbeforeunload事件

    记录知识点背景:在做一个h5项目时,在统计事件时有这样一个需求, 希望能统计到用户是从第几页离开的,用到了这个知识点.在此记录. window.onunload 1.定义和用法 onunload事件在 ...

  3. JS之onunload、onbeforeunload事件详解

    简介 onunload,onbeforeunload都是在刷新或关闭时调用,可以在<script>脚本中通过 window.onunload来调用.区别在于onbeforeunload在o ...

  4. 160503、onunload、onbeforeunload事件详解

    最近项目中做到一个功能:在上传页面用户开始上传文件之后用户点击任意跳转都需要弹出提示层进行二次确定才允许他进行跳转,这样做的目的是为了防止用户的错误操作导致这珍贵的UGC 流失(通常用户在一次上传不成 ...

  5. onunload、onbeforeunload事件详解--zhuan

    最近项目中做到一个功能:在上传页面用户开始上传文件之后用户点击任意跳转都需要弹出提示层进行二次确定才允许他进行跳转,这样做的目的是为了防止用户的错误操作导致这珍贵的UGC 流失(通常用户在一次上传不成 ...

  6. iphone上click事件不触发的问题解决。

    iphone上click事件不触发的问题解决. //在ID为jsProvince上有这么一个事件: $('body').on('click', '#jsProvince', function(e){ ...

  7. onunload与onbeforeunload事件解析 标签: 浏览器 2017-04-10 09:46 45人阅读 评论(0)

    注:只测试了chrome和IE浏览器的表现情况 onunload事件 //JS Document window.onunload = onunload_message; function onunlo ...

  8. 彻底解决低端安卓手机touchend事件不触发(考虑scroll)

    本次移动端开发时遇见了安卓4.2系统不能触发touchend的问题,有以下需求. 1. 横滑轮播图 2.下拉刷新页面内容 3.body滚动条不能失效 开始在轮播图touchmove事件中阻止了浏览器默 ...

  9. Win7/Win8/Win8.1/Win10下的DragEnter DragDrop事件不触发

    Win7/Win8/Win8.1/Win10下的DragDrop事件不触发 2011-02-02  来自:博客园  字体大小:[大 中 小] 摘要:你的应用程序需要从windows资源管理器拖动文件到 ...

随机推荐

  1. systemverilog 之interface/timing region/program

    1.connecting the testbench and the design 2.verilog connection review 3.systemverilog interfaces 4.s ...

  2. leepcode - 5-16

    7.有效的括号 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注 ...

  3. 组队赛Day1第一场 GYM 101350A - Sherlock Bones (DP)

    [题意] 给你一个01串.f(i,j)定义为区间[i,j]内1的个数,求区间 [i,j,k] 中 f(i,j) =f(j,k) 的情况的子串总数,要求str[j]=='1'. (题意描述引自Ilook ...

  4. gitlab之gitlab-ci自动部署

    简介 gitlab-ci全称是gitlab continuous integration的意思,也就是持续集成.中心思想是当每一次push到gitlab的时候,都会触发一次脚本执行,然后脚本的内容包括 ...

  5. DuiLib DirectUI 界面库

    国内首个开源 的directui 界面库,开放,共享,惠众,共赢,遵循bsd协议,可以免费用于商业项目,目前支持Windows 32 .Window CE.Mobile等平台. Duilib 是一款强 ...

  6. ios弹性头部

    很久没写博客了,金天有点时间来写下,一直觉得弹性头部很炫,看起来高大上,写起来蛮简单的 层次分析 一共有3层,最底部是图像层,中间是scrollView或者它的子类,最上层是scrollView上面添 ...

  7. HDU 1071 The area ——微积分

    [题目分析] 求二次函数和一次函数围成的面积. 先解方程求出一次函数和二次函数. 然后积分. 现在还是不会积分. [代码] #include <cstdio> #include <c ...

  8. BZOJ 3130 [Sdoi2013]费用流 ——网络流

    [题目分析] 很容易想到,可以把P放在流量最大的边上的时候最优. 所以二分网络流,判断什么时候可以达到最大流. 流量不一定是整数,所以需要实数二分,整数是会WA的. [代码] #include < ...

  9. [BZOJ3378] [Usaco2004 Open]MooFest 狂欢节(树状数组)

    传送门 开2个树状数组 一个存的是下标,一个存的是数量 细节...看标称吧,懒得说了,好气啊 #include <cstdio> #include <iostream> #in ...

  10. HDU 5352 MZL's City (2015 Multi-University Training Contest 5)

    题目大意: 一个地方的点和道路在M年前全部被破坏,每年可以有三个操作, 1.把与一个点X一个联通块内的一些点重建,2.连一条边,3.地震震坏一些边,每年最多能重建K个城市,问最多能建多少城市,并输出操 ...