Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Disable opening new browser window

Disable opening new browser window

Disable opening new browser window

Hello everyone. I'm not very familiar with javascript, but need to resolve an issue.

I want to prevent user from opening new browser window while at the website. I have seen that type of functionality at test taking sites, however I couldn't look at the source code.

I don't think I can disable File->New->Window, so there must be a way to detect that user opening a window and warn user and close new window or don't let it do at all.

Your thoughts much appreciated.


RE: Disable opening new browser window

Hi Steve... Why would you want to do that? Opening new browser windows is how I view a website (I've got three Tek-tips windows alone open at the moment)

'Preventing' me from browsing your site the way I feel comfortable will only make me not want to visit it.

You are right, there is no way of stopping the user from using their 'new window' menu option. It's there for a reason.

RE: Disable opening new browser window

It's a corporate website and it's in their requirements.
So, they (corp) want to limit user session to 1 browser window. User can type new URL in address bar or use bookmark to leave site, but while on site only 1 window allowed.

Theoretically, I think that javascript on each page should check if there's another window with the same domain name exists, then close new window if that's case. But I haven't done that before, so can't elaborate much about specifics.


RE: Disable opening new browser window

A corporate web site, or intranet site? I ask because I've recently implemented an intranet site that makes use of a tabbed interface which may better suit your requirements.

Of course if it's a web site (external), I'll tell you what you need to know, but also give you an armful of reasons to take back to your client as to why it's a bad idea.

RE: Disable opening new browser window

It's an external site that serves subscribed users. Site is working, I just apply some fixes/patches using ASP (VbScript).

Thanks dwarfthrower

RE: Disable opening new browser window

OK, the following code snippets are not recommended for general use. They exploit problems with the way browsers function and employ 'bullying' tactics to try and force users to remain on one site. There is no script - short of writing some sort of activeX program that will interfere with the normal operation of the user's browser - that can possibly prevent the user from going to the 'Start' menu or their desktop and opening a new browser window.

To disable the file menu on the current window:

//Add the following to the body's onLoad event
 if(window.name != 'mynewwin'){
  self.opener = self;

Nasty stuff... it opens the URL in a new window devoid of all the browser's normal functionality - an instant Alt-F4 for me.

To break all your links so that right-clicking and selecting "open in new window" proves fruitless:

//Add the following function to your script
function doOpenURL(urlstr){

<!-- And code all your links like so -->
<a href="javascript:doOpenURL('index2.html')">Link Text</a>

To completely remove the right-click functionality:

//add the following to your script
document.oncontextmenu=new Function("alert('Bad user... bad, bad user!');return false")

You can use this to either admonish your users for daring to use their browsedr the way they see fit, or just return false and leave them wondering.

As I said before, none of this is recommended practise. These techniques are commonly employed by porn, 'warez', casino and other nefarious sites. I'm sure your client doesn't wish to be lumped into the same category as these sites. Please persuade them not to go ahead with this idea.

RE: Disable opening new browser window

thanks dwarfthrower. at this point client agreed that if user switches to another browser window, all user sessions in ASP will be cleared, thus requiring to login again

RE: Disable opening new browser window

First let me second the remarks of the dwarfthrower, the browser window belongs to the client in every sense of the word, not to the corporation.

And you seem to be on the right track using ASP sessions to control this.  Use a database to keep track of whether or not a subscriber is logged in.  If the same subscriber tries to login a second time, respond accordingly, "Sorry, it appears that you are already logged in."  When a session expires you will need to unmark that subscriber somehow, you can't count on them logging out.  Try the ASP forum for approaches to this problem.

RE: Disable opening new browser window

Just keep in mind that if user hits Ctrl-N keys (at least in IE, didn't check Netscape), it'll open a new window, which will still be within same session and all session variables will be valid.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close