PDA

View Full Version : Preventing an event bubbling to the browser



FlaminPhoenix
29 May 2009, 11:23 PM
Hi guys,

I am trying to implement shortcuts in a webpage of mine, and Im forced to use Ctrl+Shift as the key combination... Is there any way to disable IE from taking over?( and getting MY function to execute when I hit Ctrl+S?) Heres my code: :((

var binding=new Ext.KeyMap(Ext.get(document),{key:'s',
ctrl:true,
shift:true,
fn:function(){
alert('Ctrl+Shift+S(Save) Invoked!');
}
});

Also, I have observed that in some cases like Ctrl+R, if my handler function involves showing an alert, the browser doesnt refresh the page... If there are no alert statements within the function, the whole page refreshes.. Is there any workaround for this?=P~


Also, Is there anyway to prevent the browser from taking over when I hit Alt+F or similar?

PS: This is going to be implemented in an enterprise level application, so please deter from making the usual statements about my webpage overriding user preferences and how you hate such websites. Thank you in advance

Animal
29 May 2009, 11:28 PM
http://extjs.com/deploy/ext-3.0-rc1.1/docs/?class=Ext.KeyMap&member=addBinding

Animal
29 May 2009, 11:30 PM
alerts?!

Do not use the browser alert() method. It blocks the javascript thread.

FlaminPhoenix
30 May 2009, 1:18 AM
Hi animal, thanks for your quick response...but you pointed me to the extJS API documentation page... any reason in specific? 'cause its the same page which i referred to write my code in the first place...:>

I didnt know about the javascript thread block tho...(:|

Animal
30 May 2009, 1:20 AM
So you didn't see the option which would fix your problem? It's described in the detailed docs for that method if you read it all carefully.

FlaminPhoenix
30 May 2009, 1:39 AM
So you didn't see the option which would fix your problem? It's described in the detailed docs for that method if you read it all carefully.

My bad, I seem to have forgotten to post the fact that stopEvent:true, doesnt seem to work at all. This is the reason why I decided to post my problem here at the forums in the first place... :D IE goes about its own merry way(refreshes the page after executing the function defined below) even though I have :

binding.addBinding({
key:'r',
ctrl:true,
stopEvent:true,
fn:function(){
FxMessage('Ctrl+R(Reset) Invoked!');
}
});

FX Message is a local function. It puts the string passed to it in a window and slides it in and out of view....



Thanks in advance animal

Animal
30 May 2009, 5:33 AM
The stopEvent config has no effect?

Hmm. Let me check it.

Animal
30 May 2009, 5:39 AM
Looks like Ctrl/R just can't be stopped.

FlaminPhoenix
31 May 2009, 8:34 PM
hi all,

I have spent a day trying to get around this problem, and it still doesnt seem to work... Any more ideas from anyone??..

Animal
31 May 2009, 9:32 PM
Looks like CTRL/R just can't be stopped.

There's no guarantee that Javascript code gets full control of the browser.

In fact disabling refresh is a bit antisocial. I'm not surprised it's not allowed.