This script opens a window using the image dimensions as the control. When you do not want to jeopardize convention and need a Click to enlarge Button, use this code.
<script>
<!--
function imagePopUp(img) {
html = "<html><head><title>Enlarged Image</title>" + "</head><body style="margin: 0px 0; text-align:center; ">" + "<IMG src='" + img + "' BORDER=0 NAME=image " + "onload='window.resizeTo(document.image.width,(document.image.height*1.3))'>;" + "</body></html>";
popup=window.open('','image','toolbar=0,location=0, directories=0,menuBar=0, scrollbars=0,resizable=1');
popup.document.open();
popup.document.write(html);
popup.document.focus();
popup.document.close();
};
//-->
</script>
<!--
function imagePopUp(img) {
html = "<html><head><title>Enlarged Image</title>" + "</head><body style="margin: 0px 0; text-align:center; ">" + "<IMG src='" + img + "' BORDER=0 NAME=image " + "onload='window.resizeTo(document.image.width,(document.image.height*1.3))'>;" + "</body></html>";
popup=window.open('','image','toolbar=0,location=0, directories=0,menuBar=0, scrollbars=0,resizable=1');
popup.document.open();
popup.document.write(html);
popup.document.focus();
popup.document.close();
};
//-->
</script>
To call the script use a simple link.
<a href="javascript:imagePopUp('../images/yourimage.gif')">Click to enlarge</a>
This script is modified code found @ www.rgagnon.com
8 comments ↓
If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.
DCE's Most Talked About Posts
Read Full Article...
Learn to Swap your ALT and CTRL keys in Windows XP. Windows has something called Scancode keys built in (but not really); this will let you switch the positioning of your alt and ctrl key to act like an apple layout. The jump from Apple Command to CTRL is messing with my pinky so lets fix it. Read Full Article...
Read Full Article...
teşekkürler emeğe saygı..
Çok teşekkürler başarılı
I totally agree with the two previous comments (I hope they were good ones *scratches her head*)
Anyway, joke aside, I use some kind of similar script and it worked great (well almost), but there was a lil issue, when the image popped up bigger… it lost a bit of its resolution.
Could you give me a trick?
Thanks
Gerçekten çok kullanışlı popup çalışması.
@Natulcien it’s hard to understand your issue. Can you post an example?
a few errors… extra semicolon and a bit sloppy lol
other then that, it worked!
@roman, lol thanks man, 4 years later I see how nasty the code is!
[...] Here you can find information on these kind of popups: Image Popup Window/DHTML Picture Pop up Java Script Auto-Sizing Image Popup Window Script Cut & Paste JK Pop-up image viewer Javascript Popup Image Window [...]
Leave a Comment