Javascript Popup Image Window

37

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>

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.


  • izak hason says on 01.02.09 at 11:25 am comment #1

    teşekkürler emeğe saygı..

  • morinek dizayn says on 01.02.09 at 11:27 am comment #2

    Çok teşekkürler başarılı

  • Natulcien says on 08.19.09 at 11:43 am comment #3

    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

  • sahibinden says on 08.20.09 at 2:19 pm comment #4

    Gerçekten çok kullanışlı popup çalışması.

  • ardeay says on 08.28.09 at 7:57 pm comment #5

    @Natulcien it’s hard to understand your issue. Can you post an example?

  • roman says on 04.13.10 at 1:57 pm comment #6

    a few errors… extra semicolon and a bit sloppy lol

    other then that, it worked!

  • ardeay says on 05.06.10 at 7:36 pm comment #7

    @roman, lol thanks man, 4 years later I see how nasty the code is!

  • Image popups « My start to web development says on 05.23.10 at 10:51 am comment #8

    [...] 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