Due to the needs of the project, when the user clicks the back button on the page, the page is not allowed to return to the previous page. Since it cannot be achieved purely with js, the Windows host script language wsh is used, so that when the user clicks the back button on the keyboard will not return to the previous page, but clicking the back button on the browser will still be effective. (There are many specific contents of wsh on the Internet, this is just one of the applications)
The specific implementation code is as follows:
<script language=javascript>
function onbeforeunloadattachload()
{
if(pub_keycode==8)//If the key is the back key, exit is not allowed
{
event.returnValue = ;
var wsh = new ActiveXObject(WScript.Shell);
wsh.sendKeys({ESC})
}
}
var pub_keycode;//Get the key code when the cursor is on the page
function onkeydownattachload()
{
pub_keycode=event.keyCode
}
document.attachEvent(onkeydown,onkeydownattachload);
window.attachEvent(onbeforeunload,onbeforeunloadattachload);
</script>