View Full Version : referencing an open window
mread
05-13-2003, 03:13 PM
hi all
i have a js script that simply opens another window
page1.htm
<html>
<head>
<script language="javascript">
var x;
x=window.open("page2.htm","page2","width=200,height=200");
</script>
</head>
<body>
</body>
</html>
problem:
when page1.htm is refreshed, how to i determine if page2.htm is already open or not?
all ideas/solutions/advice greatly appreciated :-)
with thanks in advance, mark
cheesebagpipe
05-13-2003, 03:34 PM
That's pretty simple: if it opens, it was closed; and, if it doesn't open, it was open already. :D
Actually, I'm being serious: browsers use window names for targeting purposes, and so won't let you open a window named "foo" if you've already got a "foo" window up there. The window.open() function simply acts like a document loader.
mread
05-14-2003, 12:39 AM
Thanks for your comments Cheesebagpipe.
I do understand what you are saying, but could you show me please by modifying my code?
I'd like to be able to "test" if my window is already open by referencing it's name ('page2').
I can't test by using the variable 'x' because when the main page is refreshed, var x will always be null.
Thanks, Mark
cheesebagpipe
05-14-2003, 02:17 AM
Well, not only does window.open() function simply act like a document loader - it also returns the existing window object (for an existing window), just as it returns a new object for a newly opened window.
<html>
<head>
<script language="javascript">
var x = null;
x=window.open("","page2","width=200,height=200,left=300,top=200");
//first time: new window -- next times: same window
//returns window object for scripting use
if (x && !x.closed) {
x.document.write('Found me!');
x.document.write('<br />');
x.focus();
}
</script>
</head>
<body>
</body>
</html>
Note that this window is only opened once.
chalerese
05-15-2003, 04:25 AM
to cheesebagpipe:
how can i can close page1.htm automatically when page2.htm opens?? page1.htm is the parent window of page2.htm..
hope you can help on this.
thanks in advance.
cheesebagpipe
05-15-2003, 06:04 AM
page1.htm sounds like a file, not a window. I know people use 'window', 'browser', 'page', 'file', 'an HTML', 'my site' etc. interchangeably, but it can get confusing. If your users will be opening page1.htm in their desktop browser (main window, opened from the application) do them - and yourself - a favor: don't touch their window. They may throw something at you. :mad:
chalerese
05-15-2003, 06:46 AM
to cheesebagpipe:
i just want to hide their browser's toolbars when they visit my site.
is this possible??
please advise..
cheesebagpipe
05-15-2003, 06:56 AM
If you want to open your site in your own window, leaving the users window alone...join the club. You can remove as much chrome - almost - as you like.
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=javascript+open+window
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.