Lasse said:
Make it a link with a target:
<a href="imageWrapper.html" target="MyImageDisplay"
Then add an onclick handler for when Javascript is enabled:
onclick="myWinOpen(this)"> CLICK MED </a>
You need to cancel the default action in the onclick event attribute if
js support is enabled. Otherwise, the link will be loaded in both windows.
The myWindOpen function could be:
var myWinReference;
function myWinOpen(link) {
if (myWinReference) { myWinReference.close(); }
This is not precise. The window could be closed and the pointer in
memory would still exist (e.g.: after viewing the 2nd enlarged image).
In such case, myWinReference.close(); would do nothing or create an error.
Also, trying to close the window as the first instruction does not make
a lot of sense. If the popup is just behind the opener (and this sort of
circumstances happens often to users) and if the link.href is the same,
then clicking again on the opener link will close and then recreate the
same popup: not an efficient way to manage user resources.
var imgSize = "medium";
var popupSize = "width=600,height=480";
if (screen.availHeight < 600) {
imgSize = "small";
popupSize = "width=400,height=300";
} else if (screen.availHeight > 1024) {
imgSize = "large";
popupSize = "width=800,height=600";
}
myWinReference = window.open("image-"+imgSize+".html",link.target,
popupSize+"resizable=yes");
The OP somewhat wants to create a functionality which is already
available and implemented in the UI, at the user's discretion in MSIE 6
and Mozilla browsers.
}
The page that is loaded is an html file. It has an event handler:
Handled above.
Closing a window by clicking in its content, on an image is not
intuitive, within normal, expectable user habits. I can understand a
large button (a real button, not a link) located at the bottom of a
document, closing a document in a window that needs to be scrolled
down... but clicking on an enlarged image to closed a window is def. not
consistent with user habits. Not recommendable IMO.
Handled above, but you obviously will have to pick your own
delimiters.
/L
Btw, the poster also multi-posted in alt.html newsgroup.
DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html