specify new window with js in IE

F

Fred

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=50,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
 
I

Ivo

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=50,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
 
D

DU

Fred said:
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=50,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
 
G

Grant Wagner

Fred said:
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=50,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,status=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,status=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 <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top