Liferay DXP 2026.Q4    |    Release Webinar: 18 November 2026    |    Replay coming soon! 

Blogs

Disable browser back button

Vikash Kumar
Vikash Kumar
読了時間: 1分未満
<script type = "text/javascript" >
(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);
</script>
ページコメント

Related Assets...

結果が見つかりません。

More Blog Entries...

Himanshu Chauhan
11月 20, 2026
Tony Lim
11月 19, 2026