|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
disable new window opening
Hi all
I am looking for a method to disable a new window from being opened, whether it be from the browser menu or ctrl+n etc... Any ideas on how this is achieved. Thanks Errol187 |
|
#2
|
||||
|
||||
|
Um, not sure what you mean....you have control over the code?
|
|
#3
|
|||
|
|||
|
well as you can see I am not that clued up on javascript. The idea is to add code that if a user wants to open another browser window it will either be disabled/give a message stating this is not possible and not allow him to do this. Opening new windows is achieved by the ctrl+n or file>new>window - hpe that makes more sense
Thanks Errol187 |
|
#4
|
|||
|
|||
|
its simple
document.onkeydown = function(){ if ((event.keyCode == 78) && (event.ctrlKey)){ alert ("No new window") event.cancelBubble = true; event.returnValue = false; event.keyCode = false; return false; } } regards Ajo.K.Jose |
|
#5
|
|||
|
|||
|
This does not work fine with Netscape
Hi,
this works fine with IE, but dose not work for netscape. I use netscape 7.1, but it does not work well. |
|
#6
|
||||
|
||||
|
Can I ask why you want to prevent this? Most users don't know how to open a new window by themselves, and if they do, is it really a problem?
I doubt you will be able to stop users using the Gecko engine (Mozilla, NS, FF) |
|
#7
|
|||
|
|||
|
Hi, im rather a noob to javascript, and i need ur help.
Do any of u pros here know how to create a script that blocks ctrl n without popping up an alert. Im sure its something like the no right click script. don't ask for the reason though, its really long! |
|
#8
|
|||
|
|||
|
The code works for the crtl + n to open new window.
Do you have suggestion to disable the new window creation via the browser menu File - New - Window? Thanks, |
|
#9
|
|||
|
|||
|
The "Ctrl"+"n" is a shortcut, that is ei. not used by the Gecko Engine. Wich means, that you will need to find out all the possible ways of killing shortcuts. As i can set my own shortcuts. Thus your script will not work. Why is it that it is important that the user cannot redirect from your site in a new window ?
- Pheifel |
|
#10
|
|||
|
|||
|
The reason to block new window creation is that:
When you open a new window with ctrl+n or menu bar, the new window created from the old window will share the same session (for server point of view) with the old window. If you change things in one window, the other window's context also changes since the server side treats the two windows as one session. But if the new IE window is opened with Start-Programs-Internet Explorer, the new window will be different session. Its context will be independent. Ajok's code can be used to block the ctrl+n method to open new window. But we also need to block the menu File-New-Window method. Any suggestion? thanks, |
|
#11
|
||||
|
||||
|
Quote:
I'm still not following - why is this a problem? Browsers have always operated like this - it is by design. If a user is advanced enough to know how to open a new window, then I'm pretty sure they understand the effect this will have. |
|
#12
|
|||
|
|||
|
Quote:
I also need exactly the same kind of functionality, that is, a way to prevent or at least detect new window opening. The reason in my case is performance optimization in a statefull screen flow. We have built session handling so that multiple screens (normally from 1-3) are grouped together so that their session handling is managed in the group level; session management is "automatic" within the group and session is automatically cleaned when navigating outside of this group. This works perfectly in case the user only has one window open, because then we can clean the session when leaving the group. However, because from the server point of view we don't know when the user has created a new window, we might accidentally clean the session when the user navigates with one window out of the group even though he/she still has another window pointing to a screen in that group. For this reason it would be a nice feature to detect the "create new window" event and then possibly put some kind of flag to request to inform the server of this event. |
|
#13
|
|||
|
|||
|
Hello Ajo,
This does work but now even my ENTER key does nothing. But if I remove your code, then my ENTER key works again. I am on IE v6 Quote:
|
|
#14
|
|||
|
|||
|
Hi emccar,
Sorry for the late reply, I was on vacation. I have gone through the code again, it works fine. Please find the code here <html> <script language="javascript"> document.onkeydown = function(){ if ((event.keyCode == 78) && (event.ctrlKey)){ alert ("No new window") event.cancelBubble = true; event.returnValue = false; event.keyCode = false; return false; } } function doBtnAction(){ alert("i am cool") } </script> <body> <input type="textbox"></input> <input type="button" value="submit " onclick="doBtnAction()"></input> </body> </html> i find that when i am in text field and pressing ENTER the focus is not moving to the button. did you mean this?? we can prevent Ctrl + n with this code, but if you hide menubar(menubar="0") , when you open the window then there is no way to open a new widow. Regards Ajo |
|
#15
|
|||
|
|||
|
disable new window opening
slightly late but thanks for replys guys....
errol187 |
|
#16
|
||||
|
||||
|
This thread disturbs me.
I don't think websites should have control over how my browser operates. Nontheless, errol187, which solution have you used? did you popup a new window without a menu and disable the shortcut using ajok's javascript? |
|
#17
|
|||
|
|||
|
Here's MY explanation as to why I'm trying to prevent users from opening a new window: I am developing a browser based game. "Script Kiddies" like to open two windows with the same page, essentially logging in twice, and then hit the submit button on each page at the same time. I've seen it happen, and I've even done it myself. This reaks havoc on the game economy as players are able to duplicate transactions. Remember "duping" in Diablo? Yeah - like that, but worse. I need to prevent users from having two windows open to my game, plain and simple. I've prevented them from using their account on two different browsers (IE and Firefox for example) but I'm still stuck as to how to stop them from using two windows created by the same browser, since sessions carry over |