JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 30th, 2004, 04:50 AM
errol187 errol187 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 errol187 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Thanks
Errol187

Reply With Quote
  #2  
Old March 30th, 2004, 08:35 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Posts: 2,056 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 44 m 22 sec
Reputation Power: 0
Um, not sure what you mean....you have control over the code?

Reply With Quote
  #3  
Old March 31st, 2004, 04:36 AM
errol187 errol187 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 errol187 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Thanks
Errol187

Reply With Quote
  #4  
Old April 28th, 2004, 12:30 PM
ajok ajok is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 ajok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

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

Reply With Quote
  #5  
Old May 3rd, 2004, 05:07 PM
test_111111 test_111111 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 test_111111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old May 3rd, 2004, 07:43 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Posts: 2,056 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)

Reply With Quote
  #7  
Old May 13th, 2004, 07:04 AM
dranfragoon dranfragoon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 dranfragoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face

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!

Reply With Quote
  #8  
Old May 18th, 2004, 05:05 PM
xiaoxin xiaoxin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 xiaoxin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Thanks,

Reply With Quote
  #9  
Old May 18th, 2004, 05:56 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 14
Send a message via MSN to Pheifel
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

Reply With Quote
  #10  
Old May 19th, 2004, 11:14 AM
xiaoxin xiaoxin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 xiaoxin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Any suggestion?

thanks,

Reply With Quote
  #11  
Old May 19th, 2004, 07:54 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Posts: 2,056 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #12  
Old May 24th, 2004, 08:30 AM
Soul Soul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 Soul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #13  
Old October 10th, 2004, 04:40 AM
emccar emccar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 emccar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry

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:
Originally Posted by ajok
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

Reply With Quote
  #14  
Old October 20th, 2004, 10:59 AM
ajok ajok is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 ajok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #15  
Old December 9th, 2004, 06:02 AM
errol187 errol187 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 errol187 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
disable new window opening

slightly late but thanks for replys guys....

errol187

Reply With Quote
  #16  
Old December 9th, 2004, 09:26 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
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?

Reply With Quote
  #17  
Old August 13th, 2005, 06:04 AM
ryanpalkovic ryanpalkovic is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 1 ryanpalkovic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Yeah. That's my two cents.

Reply With Quote
  #18  
Old August 13th, 2005, 09:17 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
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.

Reply With Quote
  #19  
Old March 16th, 2006, 09:41 AM
yifat yifat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 yifat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 sec
Reputation Power: 0
disable 'open in new window' from right click menu

hi
do you know how to cancel the option 'open in new window' you get after right click on some link?
thanks


Quote:
Originally Posted by ajok
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

Reply With Quote
  #20  
Old March 16th, 2006, 10:45 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
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 10:50 AM.

Reply With Quote
  #21  
Old March 17th, 2006, 07:13 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,029 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 1 Week 12 h 41 m 23 sec
Reputation Power: 15
Send a message via ICQ to Itsacon
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


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 592

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > disable new window opening


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap