Hi,
I want to disable Refresh and back button of a browser.
Have used Javascript function -
SyntaxEditor Code Snippet
function disableF5 (e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); };
but it is not working.
Hi Bhakti Shinde
You can use the below JS to block the browser back button :
Block back button:
$().ready(function() { if(document.referrer != 'https://localhost:8181/'){ history.pushState(null, null, 'login'); window.addEventListener('popstate', function () { history.pushState(null, null, 'login'); }); } });
assif_tiger wrote:
Hi assif_tiger,
It worked. Thank you !!!
Can you please help me with the code to disable Refresh?
I am using below code but it is not working properly.
history.pushState(null, null, document.URL); window.addEventListener('popstate', function () { history.pushState(null, null, document.URL); });
Bhakti Shinde wrote:
Happy to know It works for you :)
Perhaps coming to Browser Refresh...
As of Breaking fundamental browser features is never a good idea !!!
Rather than blocking F5, just warn the user when they leave the page while the said process is happening. More often than not they're clicking the refresh button rather than pressing F5 anyway.
This will disable F5, but not the actual refresh function:
document.onkeydown = function (e) { if (e.keyCode === 116) { return false; } };
Thank you, It is working fine for F5 But as per my application requirement, wanna make it run for refresh button also.
Hi Bhakti,
you can use below javascript code to disable Refresh and back button of a browser.
document.onkeydown = function (e) { return (e.which || e.keyCode) != 116; }; history.pushState(null, document.title, location.href);window.addEventListener('popstate', function (event) {history.pushState(null, document.title, location.href);});
Pratham wrote:
Hi Pratham,
Please find attached screen shot
I used the same in preparation action as below. But it is not working. When open in browser, it still is allowing to refresh the page.
add javascript to the module.
I have added javascript to the module.
And when open in browser, clicked on Refresh.
Still it is allowing to refresh the page.
It is working fine for F5 button but when user clicks on the refresh or back option provided to the right of browser, it is allowing to refresh or back the page. How this option can be restricted?
Hi!
Please, try to put this code inside of Menu JavaScript Webblock:
history.pushState(null, null, document.URL);window.addEventListener('popstate', function () { history.pushState(null, null, document.URL);});
I hope it will helps you (works in Chrome, FF, IE, Edge).
Thanks and Best Regards,
Nuno Pereira
Nuno Gonçalo Pereira wrote:
Hi Nuno Gonçalo Pereira,
I tried to put this code in Menu web block but it is not allowing to type inside menu web block.
Yes it is the same.
Bhakti you must open healthCalculator eSpace and do it there
Regards