onbeforeunload

Unable to handle onbeforeunload event using Angular Service

余生长醉 提交于 2019-12-22 10:07:44
问题 I have the following callback for my onbeforeUnload event in one of my service. In my app.run block I have: window.onbeforeunload = Services.beforeWindowClose; and this method is in a service: this.beforeWindowClose = function (event) { var currentState = $state.current.name; if (currentState !== constant.LOGOUT) { $rootScope.$broadcast("close"); if (Utilities.isSavePending) event.returnValue = constant.MSG; } } In my controllers I have : $scope.$on("close", function () { Utilities

IE9 onbeforeunload called twice when window.location changed in button event… minimal reproduction

人走茶凉 提交于 2019-12-22 08:08:26
问题 I've been hammering and hammering at this and just can't get anywhere. I have a cancel button that does a "window.location = '404.htm';" when clicked. The onbeforeunload handler fires twice, but only if the user clicks "Stay on this page" to the first dialog. A normal navigation (page refresh, going to home page) the onbeforeunload handler only fires once. I've managed to repro the behavior with a minimal amount of HTML and script: <!DOCTYPE html> <html> <head> <title>Test page</title> </head

“Unknown Exception” when cancelling page unload with “location.href”

流过昼夜 提交于 2019-12-22 07:28:13
问题 I'm capturing the window.onbeforeunload event using the following code: window.onbeforeunload = function (evt) { if(checkIsDirty()) { var message = 'If you continue your changes will not be saved.'; if (typeof evt == 'undefined') { //IE evt = window.event; } if (evt) { evt.returnValue = message; } else { return message; } } } When I click 'Cancel' in the resulting confirmation, I get the error "Unknown Exception" and the following is highlighted by the debugger: onclick="location.href='/

Running server-side function as browser closes

 ̄綄美尐妖づ 提交于 2019-12-22 04:47:15
问题 Background: I'm creating a very simple chatroom-like ASP.NET page with C# Code-Behind. The current users/chat messages are displayed in Controls located within an AJAX Update Panel, and using a Timer - they pull information from a DB every few seconds. I'm trying to find a simple way to handle setting a User's status to "Offline" when they exit their browser as opposed to hitting the "Logoff" button. The "Offline" status is currently just a 1 char (y/n) for IsOnline. So far I have looked into

Perform an asynchronous service get when closing browser window / tab with Angular

回眸只為那壹抹淺笑 提交于 2019-12-21 20:34:07
问题 I'm currently trying to make an Angular app make an API service call when the user tries to navigate away from my page. Either by closing the tab / window, or typing in an external URL. I've tried to implement several different ways I've seen described here on stackoverflow questions, but none seem to have the desired effect. Some mention sync ajax requests which have been, or are in the process of being deprecated in onbeforeunload on Chrome. Others advise the use of XMLHttpRequests, which

How to prevent page navigation until ajax call is complete

空扰寡人 提交于 2019-12-21 05:34:08
问题 So I have an ajax call to bring down several dozen chunks of data all several megabytes in size, afterward storing the data locally via the html5 filesystem api. I wanted to prevent the user from navigating away from the page before the ajax calls were done. I decided to explore the onbeforeunload event, to have it notify that the user should stay on the page until the ajax calls are complete. I set the following before the AJAX call and at the end/success of the AJAX call I reset the window

Executing a php script in javascript?

谁都会走 提交于 2019-12-19 11:55:30
问题 I'm trying to run a quick php script when users leave my website, and also pass a variable from my javascript to php but i'm not quite sure how to include the php file and pass it a var. But it's not actually running the php script. any ideas? (the javascript gets the username from an external activity function, and i know that works i tested the var on an alert and its there.) My JavaScript: <script language="javascript" type="text/javascript"> var username = null; function GetUsername

Dismiss “Confirm Navigation” popup with Watir

无人久伴 提交于 2019-12-19 06:24:10
问题 I am trying to dismiss "Confirm Navigation" popup. This is how it looks like in Chrome. To see the popup: require "watir-webdriver" browser = Watir::Browser.new browser.goto "http://www.gravityforms.com/demo/wp-admin/admin.php?page=gf_new_form" browser.text_field(:id => "user_login").set "demo" browser.text_field(:id => "user_pass").set "demo" browser.button(:id => "wp-submit").click browser.refresh At the moment I override onbeforeunload when I visit the page, as suggested at http:/

Cancel onbeforeunload event handler?

无人久伴 提交于 2019-12-19 05:06:48
问题 I have an onbeforeunload event handler attached to the page which executes every time the page reloads / gets redirected. window.onbeforeunload = function() { console.log("do something");} I do not want this script to run during my tests. I want to disable it in my own test environment. Is there some way to unbind this onbeforeunload event? I am using JavaScript, with jQuery as the framework, so an answer in jQuery would be good. 回答1: In javascript functions can be overwritten. You can simply

Displaying a custom dialog when the user exits the browser?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 03:41:33
问题 Yes, I realize this is horrible UI and bad accessibility wise, but I am forced to seek out the options due to contracted work ( to which I didn't initially agree upon and am stuck with ). I know that you can assign an event handler to onbeforeunload like: window.onbeforeunload = function() { return 'You have unsaved changes!'; } That would bring about a dialog generated by the OS/browser which cannot be customized. It would ask you to Cancel your request or go on. So far it seems the only way