onbeforeunload

window.onbeforeunload in javascript

感情迁移 提交于 2019-12-11 02:03:57
问题 I'm using javascript window.onbeforeunload function to show an alert to user whenever user tries to leave the page without submitting the data. This functinality is working fine. Problems comes in IE (only) where the window.onbeforeunload event fires even on click of internal links like <a class="editlink" onclick="fnEditLink(this);" href="javascript:void(0);" > <img src="/images/newstyle/pencil.png" alt="edit" /> Edit </a> This is an internal link that is used to edit grid row without making

Strategies for preserving form data ( on tab/browser close )

血红的双手。 提交于 2019-12-10 15:56:37
问题 I have an issue with a task management application where occasionally users close their browsers/tabs and the information which they type goes away because they accidentally close a browser/tab, resulting in the loss of the text which they've entered ( and some can spend half an hour entering in text ). So I have to provide a solution, I have a couple ideas but wanted input on the best to go with, or if you have a better solution let me hear ya. Option 1: On the window.onunload or possibly

Prevent onbeforeunload function from pausing javascript timer

我的梦境 提交于 2019-12-10 15:16:22
问题 In my webpage, I have a countdown timer using javascript's setTimeout() . function Tick() { if (RemainingSeconds <= 0) { alert("Time is up."); return; } RemainingSeconds -= 1; ElapsedSeconds += 1; UpdateTimerDisplay(); window.setTimeout("Tick()", 1000); } I also have a function triggered on onbeforeunload to "prevent" the user from leaving the page. window.onbeforeunload = function () { if (!isIEAjaxRequest) { return "You should use the logout button to leave this page!"; } else {

Detecting page unload in angularjs

别来无恙 提交于 2019-12-10 12:58:44
问题 I have a javascript object which I need global to my angularjs application. When the application is about to be unloaded (due to a page refresh or some other scenario), I would like to persist the object to browser storage. I believe adding the object to $rootScope would fulfill the first requirement of making the object global, but writing the object to storage during the onbeforeunload event, would require access to the $rootScope variable. Is it possible to detect a page unload event in

Unexpected performace.navigation.type onbeforeunload

五迷三道 提交于 2019-12-09 22:20:01
问题 I'm trying to handle some logic on before unload and I don't want that logic to run if the user is reloading the page or going back. I've set up something like this. window.onbeforeunload = function(e) { if(window.event && window.event.clientX){ //IE //some logic } else if (e.currentTarget.performance.navigation.type === e.currentTarget.performance.navigation.TYPE_RELOAD) { // another logic } else if(e.currentTarget.performance.navigation.type === e.currentTarget.performance.navigation.TYPE

Run Javascript code only if 'beforeunload' function returns true

ε祈祈猫儿з 提交于 2019-12-08 19:16:02
问题 I'm using JQuery to capture the unload event when a user navigates away from a page. This works just fine, but I have data that needs to be saved only in the event that the user really wants to leave. Here's my catch-22. If I save the code too early and the user doesn't want to leave, I've spoiled the state of the web service backing the code. Therefore I need to accomplish the near insurmountable task of executing code only if the 'beforeunload' dialog returns true. $(window).on(

IE9 firing onbeforeunload event when the window opens

南笙酒味 提交于 2019-12-08 14:04:40
I'm building a site using the JFileUpload applet and want to handle the closing of a page in a certain way. JSTransferCancelled is called when the applet is cancelled. The following code is what I'm using to handle these events and it works in all browsers except IE. function JSTransferCancelled(){ bCancel=false; $.post("cancel.php"); self.close(); } $(window).load(function(){ $(window).bind('beforeunload',function(){ document.uploader.setEnabled(false); if(bCancel){ document.uploader.cancel();} }); }); I open the page with the uploader on it in a new tab from the main site and want to close

Can I prevent onbeforeunload from being called when clicking on an anchor tag?

拥有回忆 提交于 2019-12-08 13:28:45
问题 In head: <head> <script type="text/javascript"> $(document).ready(function() { $("#anchor_id").click(clickHandler); window.onbeforeunload = confirmExit; }); function clickHandler() { /* hide/show some hidden div's */ $("body").append("<p>Hi there</p>"); } function confirmExit() { return "There are some unsaved changes on page."; } </script> </head> In body: <a id="anchor_id" href="javascript: void(0);">Click Me</a> Is it possible to prevent onbeforeunload from being called when clicking on

Don't have time to send get request on window unload

僤鯓⒐⒋嵵緔 提交于 2019-12-08 03:49:07
问题 I want to notify the server on user closes browser window. I tried all of the $(window).bind("beforeunload", function() { $.get("${contextPath}/notify?direction=logout"); }); and $(window).unload( function() { $.get("${contextPath}/notify?direction=logout"); }); and $(window).unload(function() { $.ajax({ url: "${contextPath}/notify?direction=logout" }); }); but neither work well, despite the fact, that it is said in manual that it probably should. In Firefox I have no notifications only on

window.onbeforeunload not displaying the alert box

試著忘記壹切 提交于 2019-12-07 00:41:17
问题 I just want to show a message before leaving the page, but my code doesn't works: window.onload=function(){ alert("Page with a digital clock"); setInterval(clock,1000); } window.onbeforeunload=function(){ alert("Are you sure to leave this page?"); } The "onload alert" works fine, but the second is not working.. 回答1: You can't put an alert inside onbeforeunload. Most browsers will do this for you so you don't need to handle it, you need to return the confirm message to the method instead: