Welcome to WebmasterWorld Guest from 54.198.46.95

Forum Moderators: open

Message Too Old, No Replies

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)

10+ Year Member



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){

pointer=window.open(pageurl,winname,
"width="+(700)+",height="+(384)+",toolbar=yes,directories=yes,
menubar=yes,status=yes,resizable=yes,location=yes,scrollbars=1,copyhistory=no");

pointer.focus();

return pointer;

}

</script>

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>
</tr>
<tr>
<td width="250" height="50" valign="top" align="right"><a href='javascript:;' OnClick='window.close();'>Close this window</a>
</td>

Any ideas what could be wrong? I am using NN 4.7.
Cheers
:-)Isa

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

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

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



window.close only works if the window was opened by JavaScript...
1:02 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



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.
/Isa
7:04 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



ISa71,

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

to

<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();'>

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

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

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



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?

Cheers
:-)Isa

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

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



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

function shrinkBrowser(url){
window.open(url,"","width=400,height=450,scrollbars=no,toolbar=no,status=no,resizable=no");
}

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

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

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

subwinopen("http://www.xxx.xx","window1")

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)

10+ Year Member



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... ;-)!
Isa
 

Featured Threads

Hot Threads This Week

Hot Threads This Month