Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,446
    Thanks
    17
    Thanked 273 Times in 273 Posts

    Fullsize image window popup script.

    This converts an ordinary 'opens in the same window' HTML page into one with a fullsize click to close popup window. Just link to the script. You can make it ignore URLs you don't want to link to by changing the start and end of the count.

    Code:
    function showImg(URL){
    var imgPage="<html><head><title>Click to Close  " + URL + "</title><style>body{background-color:#333;color:#d0ffd0;text-align:center}table{width:100%;height:100%;text-align:center}td{text-align:center;vertical-align:middle}img{border:5px solid #d0ffd0}<\/style></head><body onLoad='self.focus();' onClick='self.close();' ><table><tbody><tr><td><img src='" + URL + "'><\/td><\/tr><\/tbody><\/table><\/body><\/html>";
    var mywin=open('','','scrollbars=0,toolbar=0');mywin.document.write(imgPage);mywin.document.close();}
    function popupWindows() {
        if(!document.getElementsByTagName) {
             return;
        }
        var anchors = document.getElementsByTagName("a");
        for (var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            var imgURL = anchor.getAttribute("href"); 
    	anchor.setAttribute("href","#");
    	anchor.setAttribute("onClick","javascript:showImg('" + imgURL + "');");
    }}
    window.onload = popupWindows;
    Here it is in action. It can be a little wonky at times.

    http://ronbeau.50webs.com/newalbum/images2.html

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Your code will not work in IE. IE does not consider the events as attributes, thus it has another event model. Moreover: the token javascript: is medieval and useless. The modern JavaScript simply uses events to call a function.

    Why don't you have the patience to learn some real JavaScript instead of posting inefficient and wrong codes packed up as useful?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Quote Originally Posted by Kor View Post
    Why don't you have the patience to learn some real JavaScript instead of posting inefficient and wrong codes packed up as useful?
    Seconded. Please refrain from vomiting your undigested code over this group.
    Last edited by Philip M; 09-27-2010 at 06:34 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •