views:

46

answers:

3

As per my knowledge we can disable ctrl+N key for new window with the following javascript code :

document.onkeydown = function() { alert(event.keyCode) if ((event.keyCode == 78) && (event.ctrlKey)) { alert ("No new window") event.cancelBubble = true; event.returnValue = false; event.keyCode = false; return false; } }

In my case there are 3 frames with one of them fixed (menu bar where I can put this code), but this event is not caught if the focus is in some other frame. How can I implement this restriction globally on a browser window?

+1  A: 

I don't think you are allowed to control the browser in this way from a web page (nor should you be)

barrylloyd
+2  A: 

you'll have to include the script for each document (frame). if all the frames are pulling from the same domain, you should be able to do this from a single point of entry, using the window.frames collection and working your way down to the document object for each frame.

also your script only works in IE.

also this is a terrible idea. you shouldn't be taking over people's browser functions.

lincolnk
@lincolnk: Thanks for the comment but I require this because the server side code(which will take sometime to fix and release) uses session variables which get shared in two browser windows with same session. Can you please share a small piece of code to handle this generically for all the frames?
Tushu
A: 

While concerns such as these are often legitimate, trying to do things such as preventing key combos, or a right-click are actually bad for your site. Consider this:

A user expects their browser to work in a certain way. When you tamper with this functionality, the user can become frustrated. They may think that your site is broken, and leave.

When you attempt to prevent a user from performing built-in actions, you are essentially policing their behavior. This conveys to the user that you do not trust them to use your site unless under your supervision. The user will feel insulted, and leave.

What happens if a user has JavaScript disabled? Or if they have a custom rule-set that prevents websites from changing their browser's behavior?

What's so bad abut opening a new window? If it's a security concern, then that should be properly fixed. If the user has these thoughts they may feel insecure, and leave.

These (among many other) things must all be considered before launching a site. Hopefully this helps you while working on your project.

sigint
@sigint : Thanks for the comment but I require this because the server side code(which will take sometime to fix and release) uses session variables which get shared in two browser windows with same session. Can you please share a small piece of code to handle this generically for all the frames?
Tushu