onbeforeunload

onBeforeUnload doesn't call methods, browser closes too fast?

醉酒当歌 提交于 2020-06-01 07:40:07
问题 I'm trying to call a method in the beforeunload event handler. It seems like the browser is closing too fast. Here is my code: @HostListener('window:beforeunload', ['$event']) onBeforeUnload(): boolean { let logout: any; logout = logout(); while (logout = false) { console.log("session not ended") } return true; } public async logout(): Promise<boolean> { this.userSessionService.EndSession(this.userSessionId); this.oauthService.logOut(false); return true; } What I want to happen is when a user

How to logout during onbeforeunload/onunload using Javascript

China☆狼群 提交于 2020-04-28 19:57:51
问题 <script type="text/javascript"> window.onbeforeunload=before; window.onunload=after; function before(evt) { var message="If you continue, your session will be logged out!"; if(typeof evt=="undefined"){ evt=window.event; } if(evt){ evt.returnValue=message; } } function after() { var flex=document.${application}||window.${application}; flex.unloadMethod(); //calls the flex class containing the "unloadMethod()" which //calls the logout.jsp that does the actually dropping of credentials } <

当用户关闭浏览器时弹一个确认对话框,当程序自动关闭这个页面时无需弹确认对话框

大兔子大兔子 提交于 2020-03-04 18:06:22
最近工作中有个需求:当用户关闭浏览器时弹一个确认对话框,当程序自动关闭这个页面时无需弹确认对话框。 现在把做完的功能记录下来。 这里用到onbeforeunload事件: 目前三大主流浏览器中firefox和IE都支持onbeforeunload事件,opera尚未支持。 关闭浏览器时会触发onbeforeunload事件,当程序自动关闭这个页面时则调用u3dCloseWindow()方法。 js代码如下: <script type="text/javascript"> var flag = true; function u3dCloseWindow() { flag = false;   window.opener = null; window.open(' ', '_self', ' '); window.close(); } window.onbeforeunload = function() { if(flag) { return "未答完时请勿关闭窗口,否则成绩将不做保存!"; } } </script> 来源: oschina 链接: https://my.oschina.net/u/554982/blog/64932

Removing event listeners before leaving a page

岁酱吖の 提交于 2020-02-25 09:37:54
问题 I've developed a javascript drag and drop that mostly uses the standard 'allowdrop', 'drag' and 'drop' events. I wanted to customise the 'ghosted' dragged object, so I've added a display:none div that get populated with the innerHTML of the draggable element and made visible (display:block;) when the user starts dragging. The draggable div is absolutely positioned and matches the mouse movements. For this I needed to add 3 event listeners to document.body. They are as follows: document.body

Ajax call not working in onbeforeunload event [duplicate]

心已入冬 提交于 2020-01-25 10:29:09
问题 This question already has an answer here : How to execute ajax function onbeforeunload? (1 answer) Closed 5 years ago . I have functionality in which I need to make a ajax call to update the database value before closing the browser using 'X' button of browser. I have used below code in the header of associated file: $(document).ready(function() { window.onbeforeunload = function(){ $.ajax('<?php echo base_url();?>index.php/ajax/myfunction?a=4'); } }); On closing the browser the function

WebBrowser Control prevent Next Url navigated

余生颓废 提交于 2020-01-13 07:32:43
问题 I wonder if there is a anyway to remove the WebBrowser Message are you sure you want to navigate away from this page When I try to navigate another url, it happens. I tried this methods e.Cancel = False WebBrowser1.Dispose() WebBrowser1 = New WebBrowser WebBrowser1.ScriptErrorsSuppressed = True WebBrowser1.Navigate(New Uri("https://www.google.com")) 回答1: That is coded into the website, so you'd have to inject some Javascript into the page to override the prompt. Be careful with this, though.

beforeunload on Chrome

喜你入骨 提交于 2020-01-10 05:59:21
问题 I have this code that will redirect the user to another URL whenever he/she closes the page. This is working on Firefox, IE, Safari, etc. but not in Chrome. It won't redirect the user to new URL. Thanks! jQuery(document).ready(function() { jQuery(window).bind('beforeunload', function(e) { location.href="http://google.com/"; return "Before you leave, please take a look at this limited time offer."; }); }); 回答1: Not sure it is what you are looking for, this will redirect user if he choices to

Problems with onbeforeunload

北战南征 提交于 2020-01-07 03:14:15
问题 I have problem with onbeforeunload and preventing user from exit the page: When user want to exits i want to redirect him on other page, without any warning or pop-up I try to popUp that page, but browser popup detect this and block it. Is something like that possible? Have a nice day! 回答1: Browsers disallow that sort of behavior since it's normally a very unpleasant thing for the user. 回答2: Yes, i know this is unpleasant, but it is mainly internal page, so it is targeted group of users ( i

Accessibility of confirm dialog in chrome

你。 提交于 2020-01-06 07:09:08
问题 The confirmation dialogues in chrome are not accessible to JAWS screenreader (Version 18.0.2945). I experienced that with a simple onbeforeUnload dialog as well as with a javascript confirm dialog. The text in the dialog will not be read. Did anyone experience similar problems or knows an answer? 回答1: As of today, 18/09/2017, this is a jaws issue. The code works on all other major browsers. There is no solution at present. Just for your information, alert and prompt have the same problem.

How to Disable Are you sure you want to navigate away from this page? messagebox in onbeforeunload

强颜欢笑 提交于 2020-01-06 03:51:06
问题 I use the following onbeforeunload for call when the browser close.I get the alert properly also i get the Are you sure you want to navigate away from this page? message box automatically generate by the web browser.But I no need to display that message box when the browser is close.How to disable Are you sure you want to navigate away from this page? messagebox? window.onbeforeunload = function(event) { if($.browser.msie) { alert('Test'); return false; } } 回答1: Don't return a value, ie: