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:
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  
Old March 30th, 2004, 03: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, 07:35 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Um, not sure what you mean....you have control over the code?
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old March 31st, 2004, 03: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, 11:30 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
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, 04: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, 06:43 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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, 06: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, 04: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, 04: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: 5
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, 10: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, 06:54 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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, 07: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, 03: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, 09: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, 05: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, 08: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,890 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 4 m 48 sec
Reputation Power: 8
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, 05: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