Forum Moderators: open

Message Too Old, No Replies

How to protect a pop-up window from reuse?

         

softins

10:11 am on May 24, 2007 (gmt 0)

10+ Year Member



I have an application that creates a new IE window using Javascript window.open() in response to a user click. This new window contains the application, which needs to keep running until the user chooses to close it.

How can I protect the new window from being accidentally re-used when the user subsequently clicks on a URL shortcut or a link in an email?

I know about turning off the IE Advanced setting "Reuse windows for internet shortcuts", and also about turning off "use DDE" for the open method of URLs and http pages. Although these overcome the problem, they are global to the system, and I don't want to require all my users to do this.

What I am looking for is a way for a window to tell the OS "you can't reuse THIS window".

Is this possible?

Cheers
Tony

Dabrowski

11:01 am on May 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've never heard of anything like that in JS. I'm 99% sure it can't be done.

Trace

4:12 pm on May 24, 2007 (gmt 0)

10+ Year Member



You can specify a window name in the window.open() function.

Example, if you did this; window.open('http://www.example.com', 'myWindow')

Everytime you click that link, it will always load in the same window; the one named 'myWindow'

So what you would want to do is make sure that every time that link is clicked a new unique name was supplied, forcing a new window to open.

Quickly I've come up with something like this;

<script type="text/javascript">
var windowVar;
var curmin;
var cursec;

function getTime(){
var curtime = new Date();
curmin = curtime.getMinutes();
cursec = curtime.getSeconds();
}

function openWin( addy, windowName ){
getTime();
windowName = windowName + curmin + cursec;
// windowName will be something like 'myWindow153'
windowVar = window.open( addy, windowName );
}
</script>

<a href="#" onClick="openWin( 'http://www.example.com', 'myWindow' ); return false;">Click me</a>

There's probably a way better way of doing this but it should point you in the right direction.

Trace

4:14 pm on May 24, 2007 (gmt 0)

10+ Year Member



Dang - just re-read your problem. I'm way off.

Sorry, disregard my last post.

rocknbil

6:23 pm on May 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No trace - that should work. He/she doesn't want the window re-used on "other" new window links. Althouh it doesn't tell the OS not to use this window, if a mail link is clicked or a link is clicked that specifies a target ("new window" "_blank") it should open it's own. By assiging an id to the window it should keep itself out of the other new windows' ways.

I would just simplify it a bit. :-)


function newWin(url,w,h) {
var day= new Date();
var id = day.getTime();
var ww = w+75;
var wh = h+125;
if ((screen.height) && (wh > screen.height-100)) { wh = screen.height-100; }
var params = 'width='+ww+',height='+wh+',scrollbars,resizable';
var win = open(url,id,params);
}