Napisany przez: sauber94 24.01.2020, 13:07:16
Cześć.
Potrzebuję skryptu do przeglądarki internetowej Chrome, który zablokuje możliwość cofania do poprzedniej strony.
Znalazłem w sieci taki o to skrypt lecz zdarzy mu się czasem nie działać. Druga sprawa to blokuje mi na niektórych stronach możliwość uzupełnienia inputów. Kod skryptu poniżej:
Kod
(function (global) {
if(typeof (global) === "undefined")
{
throw new Error("window is undefined");
}
var _hash = "!";
var noBackPlease = function () {
global.location.href += "#";
// making sure we have the fruit available for juice....
// 50 milliseconds for just once do not cost much (^__^)
global.setTimeout(function () {
global.location.href += "!";
}, 50);
};
// Earlier we had setInerval here....
global.onhashchange = function () {
if (global.location.hash !== _hash) {
global.location.hash = _hash;
}
};
global.onload = function () {
noBackPlease();
// disables backspace on page except on input fields and textarea..
document.body.onkeydown = function (e) {
var elm = e.target.nodeName.toLowerCase();
if (e.which ==8 && (elm !== 'input' && elm !== 'textarea')) {
e.preventDefault();
}
// stopping event bubbling up the DOM tree..
e.stopPropagation();
};
};
})(window);
Napisany przez: trueblue 24.01.2020, 16:13:35
Możesz obsłużyć zdarzenie beforeunload (nie działa na urządzeniach mobilnych).