...

View Full Version : Disable Hotkeys for Netscape 6 & 7?



jweaver
04-07-2003, 07:59 PM
I'm trying to figure out how to disable certain hotkeys (ctrl + n, ctrl + o, etc...) and i'm having some trouble with netscape 6 and 7 browsers. Heres what i've got right now...



// called onLoad
function WinOpen () {

try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
} catch (err) {
document.write("Sorry, you can not enjoy this site because of " + err + ".");
return false;
}

window.open("nn_keycode.htm","newWindow","titlebar=no,hotkeys=no");
}

// code on newly opened window (disabled hotkey window)
function docKeyDown (event) {

if(event.ctrlKey && event.keyCode == 78) {
alert('ctrl + n hit');
event.cancelBubble = true;
return false;
}

}

document.addEventListener("keydown",docKeyDown,false);


In this script, i'm detected for <ctrl> + <n> and it successfully detects the hotkey combo (by displaying alertbox), but it also opens up a new browser window, which i don't want.

Any ideas, or prior experience?

liorean
04-07-2003, 08:13 PM
<preaching>Trying to stop the user from opening a new window is really bad behavior from a website and should be avoided. A website is intended to be a document, not an application - and a document shouldn't be able to disable or even change any portion of the user interface. Some things in the user interface already can't be changed or stopped, even if they can be detected - and while detection might be good, changing really isn't.

In short, don't even try to do that. You can't prevent it from a user who knows the system anyway, and most mozilla users aren't just Joe Average when it comes to computer skills - it's a browser popular among web designers, scripters, programers and other computer circles.

</preaching>

Well, the fact is, I believe you can't override most of the user interface features, such as opening a new window, opening the DOM Inspector etc. That is, from my point of view, the way things are supposed to be. If you're making an application, try XUL.

jweaver
04-07-2003, 08:38 PM
Thank you, but i know the ramifications of what i am tring to do and it has nothing to do with a public website.

liorean
04-07-2003, 09:05 PM
Well, I'm sorry to say, but you'll remain limited by the rules that apply to websites even if you have an application, if you're running it as html. A xul/xbl interface to load the html document should be able to access some more features, probably also change key binding. I don't know if that's a viable solution to you, though.

jweaver
04-07-2003, 10:35 PM
Well i figured it out anyway...instead of this...


document.addEventListener("keydown",docKeyDown,false);


this worked for me...


document.addEventListener("keypress",docKeyDown,false);


keypress instead of keydown.

Dispite what you think *should* happen with the behavior of a browser liorean, certain characteristics like this are allowed, with user permission or signed scripts...maybe you should read up on that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum