homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

2 JS functions, 1 not working in NN
A JS function not working in NN when combined with function window.close

 4:57 am on Mar 19, 2003 (gmt 0)

I am using the following function:
<line breaks added to the feature string to prevent side scroll - tedster>

<script language="Javascript">

function subwinopen(pageurl,winname){



return pointer;



and it is working fine in both IE and NN.
However, when I also use the window.close function it stops working (but the window.close function works fine)in NN! In IE, both functions work.

I have the following in my code:

<a href='javascript:;' OnClick='subwinopen("http://www.xxx.xx","",450,550);'>Click here
to visit the xxx web site</a>
<td width="250" height="50" valign="top" align="right"><a href='javascript:;' OnClick='window.close();'>Close this window</a>

Any ideas what could be wrong? I am using NN 4.7.

[edited by: tedster at 6:48 am (utc) on Mar. 19, 2003]



 8:12 am on Mar 19, 2003 (gmt 0)

window.close only works if the window was opened by JavaScript...


 1:02 pm on Mar 19, 2003 (gmt 0)

DrDoc, the window where I use the two functions is opened with Javascript (in fact it is opened with the same subwinopen function). And the window.close function is the one that works. It is the subwinopen function that doesn't.


 7:04 pm on Mar 19, 2003 (gmt 0)


Change this line:
<a href='javascript:;' OnClick='subwinopen("http://www.xxx.xx","",450,550);'>


<a href='javascript:subwinopen("http://www.xxx.xx","",450,550);'>

or this may work?

<a href='javascript:;' OnClick='subwinopen("http://www.xxx.xx","",450,550);return false;'>

and this line:
<a href='javascript:;' OnClick='window.close();'>

<a href="JavaScript:window.close()">


 9:39 pm on Mar 19, 2003 (gmt 0)

Nicely spotted, Gizmare!
Yep, I'd have to second that suggestion. It should solve your problem :)


 1:16 am on Mar 20, 2003 (gmt 0)

Thanks Gizmare and DrDoc.
However, it has not quite solved the problem. What happens now (with my old code or with your suggestion) is that the web site specified in the function subwinopen opens, but in the same window. This leads me to believe that NN has a problem opening another window from a window that was already opened with JavaScript. Could this be?
The window.close function, as before, works fine.
Any ideas?



 6:09 am on Mar 20, 2003 (gmt 0)

Does the new window have a different name than the first one? If not, it will open in the same window...


 10:59 pm on Mar 20, 2003 (gmt 0)

Here is the code I use to accomplish this task. It works with NN4.7 , NN6+ and IE4+.

function shrinkBrowser(url){

<a href="JavaScript:shrinkBrowser('/Virtual-Tours/top_deck.htm');">


 12:10 am on Mar 21, 2003 (gmt 0)

The subwinopen() function you're using uses two variables - url and winname. But you're apparently not passing an explicit "winname" variable when you call the function. Just do that, and use a different winname each time you want a separate new window to open.


Also, I notice that the function you've defined already sets the size of the new window as 700x384. You could turn height and width into variables and pass them as parameters whenever you call the function, but you can't expect to override them.

For some examples, see the Generic Javascript [webmasterworld.com] thread, message number 4.


 12:29 am on Mar 21, 2003 (gmt 0)

Thanks DrDoc, Gizmare and tedster! Of course I had forgotten to name the window. I guess since it was working perfectly fine in IE, and I had used the same function on another page where there was only one window to open, I just forgot about it. Thanks for reminding my brain to start thinking again... ;-)!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved