469,287 Members | 2,767 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

specify new window with js in IE

this is a problem i can't figure out.
I can't get IE to link to a new widown with width/height attributes as i can
in other browsers. It works in NN, Op, Moz.
The code is all on the same line as per msdn
Here's the code:
...
<a href="#" target="_self" onClick="window.open('images/prod/Ggps2.jpg','GPS
II','toolbar=no,width=200,height=200,left=50,top=5 0,status=no,scrollbars=no,
resize=no');return false"><img border="0" src="images/thumb/Ggps2.gif"
alt="GPS II" width="73" height="70"></a>.
...
any help would be appreciated
Fred

Jul 23 '05 #1
3 1713
Ivo
"Fred" wrote
I can't get IE to link to a new widown with width/height attributes as i can in other browsers. It works in NN, Op, Moz.
The code is all on the same line as per msdn
Here's the code:
..
<a href="#" target="_self" onClick="window.open('images/prod/Ggps2.jpg','GPS II','toolbar=no,width=200,height=200,left=50,top=5 0,status=no,scrollbars=no, resize=no');return false"><img border="0" src="images/thumb/Ggps2.gif"
alt="GPS II" width="73" height="70"></a>.
..
Change the target to something else perhaps? That is the value of the target
attribute of the <a> element. If you specify "GPSII" as the target, chances
are it will open in that window.
By the way, any feature not listed in that third parameter will be absent
from the new window (as per msdn). If you remove every "xxxxx=no" the code
will be easier to maintain. Features that are listed are taken as wanted
even without an explicit "=yes" and will be present in the new window.
Also, may I suggest keeping it resizeable? Because why not.
Your link tag would then look like this:

<a
href="images/prod/Ggps2.jpg"
target="_self"

onclick="window.open(this.href,this.target,'width= 200,height=200,left=50,top
=50,resizable');return false" any help would be appreciated
Fred


Welcome,
Ivo
Jul 23 '05 #2
DU
Fred wrote:
this is a problem i can't figure out.
I can't get IE to link to a new widown with width/height attributes as i can
in other browsers. It works in NN, Op, Moz.
The code is all on the same line as per msdn
Here's the code:
...
<a href="#" target="_self" onClick="window.open('images/prod/Ggps2.jpg','GPS
II','toolbar=no,width=200,height=200,left=50,top=5 0,status=no,scrollbars=no,
resize=no');return false"><img border="0" src="images/thumb/Ggps2.gif"
alt="GPS II" width="73" height="70"></a>.
...
any help would be appreciated
Fred


Ivo replied to you good answers. I'll add some more comments on top of
what he said.

The 2nd parameter of the window.open call should be one string without
any blank space otherwise MSIE 5+ will behave incorrectly. I personally
think Mozilla and Opera should NOT accept blank spaces in the target
attribute value: bugfiles should be opened on this.

You also had a contradiction between href="#" and the window.open call:
in case of javascript support disabled, clicking the link would not have
loaded that Ggps2.jpg file of yours.
You can choose to not open a new window (target="_self") in case
javascript support is disabled or you can choose to open a new window
(target="GPSII") in case javascript support is disabled: whatever you
do, your href value should be the Ggps2.jpg file at least. So that the
content is accessible despite javascript support disabled.

Finally, the code given by Ivo will not compensate for usability
problems/burdens often seen by use of window.open calls:
- bringing on top a secondary window if the opener is brought back on
top of it and if the user clicks on the link again
- recycling a secondary window so that this window (and only 1 secondary
window) can serve to show enlarged images

DU

DU
Jul 23 '05 #3
Fred wrote:
this is a problem i can't figure out.
I can't get IE to link to a new widown with width/height attributes as i can
in other browsers. It works in NN, Op, Moz.
The code is all on the same line as per msdn
Here's the code:
..
<a href="#" target="_self" onClick="window.open('images/prod/Ggps2.jpg','GPS
II','toolbar=no,width=200,height=200,left=50,top=5 0,status=no,scrollbars=no,
resize=no');return false"><img border="0" src="images/thumb/Ggps2.gif"
alt="GPS II" width="73" height="70"></a>.
..
any help would be appreciated
Fred


Everyone else missed the actual problem. The window name (2nd argument of
window.open()) can not contain spaces. Change it from "GPS II" to "GPSII" and it
should work as expected. However, a better design would be:

<a href="images/prod/Ggps2.jpg" target="GPSII"
onclick="
window.open(
this.href,
this.target,

'toolbar=no,width=200,height=200,left=50,top=50,st atus=no,scrollbars=no,resize=no'

);
return false;
"><img border="0" src="images/thumb/Ggps2.gif" alt="GPS II" width="73"
height="70"></a>

Now you get a new window with the right image regardless of whether Javascript
is enabled on the user's browser or not. Not to mention, if you do this multiple
times, you could now re-factor to move the window.open() call out of the onclick
event entirely:

<script type="text/javascript">
function openFullImage(lnk) {
window.open(
lnk.href,
lnk.target,

'toolbar=no,width=200,height=200,left=50,top=50,st atus=no,scrollbars=no,resize=no'

);
return false;
}
</script>

<a href="images/prod/Ggps1.jpg" target="GPSI"
onclick="return openFullImage(this);"><img ...></a>
<a href="images/prod/Ggps2.jpg" target="GPSII"
onclick="return openFullImage(this);"><img ...></a>
<a href="images/prod/Ggps3.jpg" target="GPSIII"
onclick="return openFullImage(this);"><img ...></a>
<!-- etc -->

The only problem with any of these designs is that an overly aggressive popup
blocker might block your full image window popups, even though they were
initiated by the user.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by JD | last post: by
1 post views Thread by Kueishiong Tu | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.