I want to stop the browser request, when user clicks on any button from UI, like stop button on browser. I want to do it through javascript.
Here’s how to make your browsers stop bugging you on Windows. Google Chrome displays a small message at the top asking you to make it your default browser. Unfortunately, there’s no option anywhere in Chrome to get rid of this message for good. However, you can click “X” on this default browser prompt to dismiss it.
On Firefox’s Options screen, click “General” on the left. Deactivate the “Always check if Firefox is your default browser” option on the right. Firefox will stop asking to be your default. Stop Microsoft Edge from Asking to Be the Default Browser
But there is a problem that identical events can occur once a user clicks on the refresh button of a browser. So, to grasp whether the refresh button or back button is clicked, we will use the subsequent code. alert ("Browser back button is clicked..."); alert ("Browser refresh button is clicked...");
You can disable the ctrl+f5 and only f5 button/keypress using javascript. Below are few links you can follow up with:- But dear disabling the refresh icon on the browser is next to impossible. Like disabling the back button we manipulate with the browser history. But We cant manipulate with the browser defaults.
As Amit Doshi and Slaks code suggests you can do that. But I find it more efficient to do a try and catch.
There is only one alternative to window.stop()
so trying it first with a fallback (for Internet Explorer) is the way to go to support all browsers:
try {
window.stop();
} catch (exception) {
document.execCommand('Stop');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With