locked
Disabling back button but not for any input field RRS feed

  • Question

  • Hello
    Frnds

    I am trying to disable back button on page. I have done upto disabling it for complte page.
    But it is giving alert even inside text field if tried to delete text using backspace button. Not getting how to track
    whether cursor is inside input field or not. I want such condition which will check that cursor is inside input field.(textarea,text etc.)

    Here is my code ----


    document.onkeydown = function(e)
    {

     var e=window.event || e
     if(e.keyCode == '8') // for backspace button
     {
          alert("Back functionality is disabled.");
          return false;
     }
    }
    Wednesday, June 3, 2009 9:25 AM

Answers

  • try checking the srcElement for the source of the event to see if its coming from an input control?

    But do you really think disabling the browser back button is a good approach? In my opinion a web page should not change/disable any browser settings. If you do so, you would have to write browser sniffing code which is not considered a good practise.

    Ganesh Ranganathan
    [Please mark the post as answer if you find it helpful]
    Wednesday, June 3, 2009 7:07 PM

All replies

  • try checking the srcElement for the source of the event to see if its coming from an input control?

    But do you really think disabling the browser back button is a good approach? In my opinion a web page should not change/disable any browser settings. If you do so, you would have to write browser sniffing code which is not considered a good practise.

    Ganesh Ranganathan
    [Please mark the post as answer if you find it helpful]
    Wednesday, June 3, 2009 7:07 PM
  • Hey ganesh

    Really thnx ......
    Done..... Thank uuuu.....
    Thursday, June 4, 2009 6:15 AM