Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Disable opening new browser window

dobrios (Programmer) (OP)
20 Jul 03 18:59
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.

steve
dwarfthrower (Programmer)
20 Jul 03 19:19
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.
dobrios (Programmer) (OP)
20 Jul 03 19:40
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.

steve
dwarfthrower (Programmer)
20 Jul 03 19:46
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.
dobrios (Programmer) (OP)
20 Jul 03 20:37
It's an external site that serves subscribed users. Site is working, I just apply some fixes/patches using ASP (VbScript).

Thanks dwarfthrower
dwarfthrower (Programmer)
20 Jul 03 21:07
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;
  window.open(window.location.href,'mynewwin','fullscreen');
  window.close();
 }

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){
 window.navigate(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.
dobrios (Programmer) (OP)
22 Jul 03 17:03
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
rac2 (Programmer)
22 Jul 03 17:23
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.
LV (Programmer)
22 Jul 03 17:26
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.

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!

Back To Forum

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