I want to unblockui when stop loading page request is called.
dashboard: function(e,data) {
window.location = $("#dashboard-url").val()+"?trace_id="+data.id;
$.blockUI();
}
}
but before "window.location" page loads I press stop loading page in browser still UI is blocked.
is there any method with which I can unblock ui when stop loading page request is called.?
It is not possible to detect when the user cancel a page loading with javascript.
See this discussion: Detect when user clicks link, but aborts
Related
I'm trying to catch each page load on https://forum.vivaldi.net
//==UserScript==
//#include https://forum.vivaldi.net/*
//==/UserScript==
(function () {
window.addEventListener('DOMContentLoaded', function () {
alert('A new page is loaded');
});
})();
This will fire each time I hit enter in the address bar.
But nothing happens when I navigate from one page to another in the forum.
Why isn't DOMContentLoaded firing at each page load?
That site uses Ajaxify to automatically convert all intra-site links to XHR requests. DOMContentLoaded isn’t firing between pages because there is no new page loading - just content downloading in the background and being inserted into the current page.
You can see this in action by following the activity in the Network tab of your browser’s developer tools.
As for how to catch each page load in this instance, check out the events exposed by Ajaxify.
If I start writing post in Facebook and then either close or refresh page, Facebook somehow recognizes each of these actions (Reload site vs Leave site).
In javascript there's onbeforeunload event that gets called when webpage is about to unload, but how does Facebook manage to recognize if page unloads due to browser close or browser refresh function? Event doesn't contain that information afaik.
window.addEventListener('beforeunload', function(e) {
// this is browser refresh or close?
});
There is a way to detect when the page is being redirected?
Example, I put a timeout for X seconds and if the page wasn't redirected (the user still in the page) it will kill the timer except if the page is being redirect... because some redirections can be freeze (delay, lazy)... so it will re-program the timer instead of kill it...
the readystate will change if the page is on a redirect?
How to detect if the page is on a redirect using javascript?
Thanks
window.onbeforeunload = function(e) {
return 'Dialog text here.';
};
this function fires when the user is leaving the page, but it is very limited in what can be done in it. For example you cant fire an ajax call and wait for a return in this function.
Read more here
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
I want to prevent users from reloading the page each time to get updated dynamic content. So I have used this code:
window.onbeforeunload = function() {
return "Dont need to reload the whole page. Just reload the section";
}
It's working fine except when an user closes the browser's tab/window, the same message is showing also. But I want to show the message only for reloading/F5 button, not for closing the browser's tab/window. What event handler should I have to used for that purpose?
You can physically disable the f5 button, to get functionality similar to what you want:
Disable F5 and browser refresh using javascript
I have a web app with some 'safety' code which causes a page reload if the server (Socket.IO) connection goes silent for more than 5 seconds (generally customer site firewall/broken-proxy issues).
The Socket.IO connection stops as soon a new page starts loading, but the safety code doesn't see this. Navigating to a slow page causes the safety code to fire and jump you back to the previous page.
I need to be able to tell (just before this code causes a reload) whether the browser is currently waiting for a new (slow) page to load.
What approaches are there to doing this, other than putting a jQuery click event on every link (which would not catch navigation via the address bar)?
Thanks,
Chris.
Monitoring window.onbeforeunload would do the trick. Fires right after the user starts navigating away.
Try typing this in the Chrome Console on any page and click on any link:
window.onbeforeunload = function () { console.log("oh noes"); }
My recommendation: fix your code so that you don't reload the page when the socket disconnects. Problem solved.
Edit
I suppose you could simply set a variable such as isReloading when the page reloads. You'd need to monitor onbeforeunload as well, and check what happens first: disconnect or the unload event. If the disconnect happens first, you're getting disconnected. Trigger the isReloading flag and reload. In the onbeforeunload check whether the flag was set. Reverse the concept of checking whether a slow page is loading: check whether you are reloading.