javascript - How to prevent a user from going back/forward when they are on a page? -


i have script runs inside frame of different system (ie. phone system.) every time user clicks shift , scroll mouse, page goes , caused issue phone system.

i need stop user navigating forward or backward page controlled phone system , should open long phone system in open.

to stop navigation have done this

<script type="text/javascript">  function stop()  {      return false;  }   document.onmousewheel = stop;  window.onbeforeunload = stop;  </script> 

but displays message "are sure want leave page?" user have click on "leave page" or "stay on page" continue.

however, if user clicks "leave page" still run original issue.

is there way can stop user going back? here potential solutions think of can't apply of them

  1. make code clicks "stay on page" on user's behalf. if can clicks "stay on page"
  2. disable "leave page" button. therefore, use have no other buttons click "stay on page".

this assumes have jquery loaded. can't test in scenario tell me if works you.

$('html').keypress(function(event) {     // 16 shift's key code     if (event.which === 16) {         event.preventdefault();     } }); 

this should prevent shift key whatever default behaviour in browser is.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -