Discuss disable new window opening in the JavaScript Development forum on Dev Articles. disable new window opening JavaScript Development forum discussing the use of JavaScript and its features as a powerful DOM manipulator. JavaScript is used in most websites to enrich the interface and enhance the user experience.
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
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.
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
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
Posts: 2,056
Time spent in forums: 5 h 44 m 22 sec
Reputation Power: 0
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)
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
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!
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
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?
Posts: 174
Time spent in forums: 43 m 46 sec
Reputation Power: 15
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 ?
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
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.
Posts: 2,056
Time spent in forums: 5 h 44 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by xiaoxin
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.
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.
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by stumpy
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.
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.
Posts: 1
Time spent in forums: 7 m 57 sec
Reputation Power: 0
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.
I don't want to use Javascript to do so, since it can easilly be disabled, so I'm going to keep looking - but that's just one reason to not allow people to open another window.
Posts: 552
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 13
limit session window to one
You are looking at this from the wrong perspective (I hope). You can control (to some extent) the document in a user's browser. You can not (ethically) hi-jack the user's browser. If you could, there would be so many people upset about it they would quickly figure out a way to prevent it (anti-spyware, anti-adware, anti-virus etc.). If you want to limit the number of Sessions, you can test for the number of instances of a session with server-side script, not with javascript.
Posts: 552
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 13
new windows and sessions
I suggest that you not use client-side javascript to try to control the number of sessions. Many users do not have javascript enabled and it can also be removed. However, it would be useful for informing users that do have it enabed as to why it is not allowed. Rather than trying to not have an alert message, I suggest that you use the alert to explain in general terms why it is not allowed. As has been mentioned, trying to hi-jack a users browser is not the correct approach to the problem. The only sure way of preventing multiple pages with the same session, as has been said, is to use server-side code.
Last edited by Mittineague : March 16th, 2006 at 09:50 AM.
Posts: 1,029
Time spent in forums: 1 Week 12 h 55 m 59 sec
Reputation Power: 15
In fact, when I come across dirty tricks like this, I genarally disable javascript, and find out how much damage it does to the programs running the site.
The behaviour of your site should NEVER be dependent on client-side applications. If a person who disables javascript can destroy your database, gain access to stuff he shouldn't, etc, your programming is just plain and simply inadequate.
Use javascript to EASE a users experience of your site, not limit it, like automatically filling out parts of forms, or give client side warnings of incorrect input, but ALWAYS make it possible to fill out the form without javascript, and always check for incorrect input on the server side, even if you already checked it on the client's side.
JS is an aide, not a tool.
__________________ This is my code. Is it not nifty?
"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams