Results 1 to 5 of 5

Thread: disable backbutton of browser

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    4

    Default disable backbutton of browser

    I had a requirement that when user opens a windowpopup on a page it should disable backbutton of the browser on load of that window. is there any way to disable backbutton in script to do that action can any one provide input on this.

  2. #2
    Sencha User paffinito's Avatar
    Join Date
    Oct 2009
    Location
    Italy
    Posts
    14

    Default

    I use this code:

    Code:
    Ext.EventManager.on(Ext.isIE ? document : window, 'keydown', function(e, t) {
        if (e.getKey() == e.BACKSPACE && ((!/^input$/i.test(t.tagName) && !/^textarea$/i.test(t.tagName)) || t.disabled || t.readOnly)) {
            e.stopEvent();
        }
    });

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    4

    Default

    Thank u for providing me the code.

    but i am looking for the scneario when the popup is opened it should disable back button of browser not on when an event occurs. and when we close poup it should allow back navigation. do you have any solution for this.

  4. #4
    Sencha Premium User
    Join Date
    Jul 2011
    Location
    Barcelona
    Posts
    4

    Default

    Just in case someone else ends up here, in ExtJS 5 this solution works, but raises a warning:
    Code:
    Ext.EventManager is deprecated. Use Ext.dom.Element#addListener to attach an event listener
    This is working fine:
    Code:
    Ext.getBody().on('keydown', function(e){
    	if((e.getTarget().type != 'text' || e.getTarget().readOnly === true) && e.getKey() == '8' ){
    		e.preventDefault();
    	}
    });

  5. #5

    Default

    no its not working for browser back button .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •