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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Newbie: Where to put the focus()-line?

    I'm using the following popup-script

    Code:
    /******************************************************* 
    IMAGEPOP 1.2
    (c) 2003, Peter Bailey, http://www.peterbailey.net
    Modified by Ryan Parman, http://www.skyzyx.com
    
    - Works in IE/Win 5+, Gecko 0.94+, Opera 7+
    - Downlevel for IE5/Mac and other non-DOM browsers.
    - Fails miserably in Opera 6
    - Not sure about KHTML browsers... 
    *******************************************************/ 
    
    // Quick Browser Sniffs
    var opera=(navigator.userAgent.indexOf('Opera') != -1) ? true:false;
    var operaVer=0;
    if (navigator.userAgent.indexOf('Opera ') != -1)
    {
    	operaSplit=navigator.userAgent.split('Opera ');
    	operaVer=parseInt(operaSplit[1]);
    }
    else if (navigator.userAgent.indexOf('Opera/') != -1)
    {
    	operaSplit=navigator.userAgent.split('Opera/');
    	operaVer=parseInt(operaSplit[1]);
    }
    var opera7=(opera && operaVer >= 7) ? true:false;
    
    var ie5mac=(navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('MSIE') != -1) ? true:false;
    var dom=(document.getElementById && !opera) ? true:false;
    
    // Positioning Differences Between Browsers
    var vertShift=100; // Default for IE/Win and Gecko
    if (opera7) vertShift=200; // For Opera 7
    
    function imgPop(imageURL, imageTarget)
    {
    	// In case there is no target specified.
    	imageTarget=(imageTarget) ? imageTarget:"_blank";
    
    	if ((dom || opera7) && !ie5mac)
    	{ 
    		var imgWin = window.open('about:blank', imageTarget ,'width=200, height=200, left=0, top=0');
    
    		with (imgWin.document) 
    		{ 
    			writeln('<html><head><title>Loading...</title>'); 
    			writeln('<style type="text/css"><!-- body { margin:0px; padding:0px; } --></style></head>'); 
    			writeln('<body onload="self.focus();"><img id="pic" style="display:none" /></body></html>'); 
    			close();		 
    		} 
    
    		var img = new Image(); 
    		img.onload = function() { sizeImgWin(imgWin, img); }; 
    		img.src = imageURL; 
    	} 
    
    	else window.open(imageURL, imageTarget);
    } 
    	 
    function sizeImgWin(win, img) 
    { 
    	var new_w = img.width; 
    	var new_h = img.height; 
    	var old_w = win.innerWidth || win.document.body.offsetWidth; 
    	var old_h = win.innerHeight || win.document.body.offsetHeight; 
    
    	if (!new_w) { new_w = old_w; } 
    	if (!new_h) { new_h = old_h; } 
    
    	new_w -= old_w; new_h -= old_h; 
    	win.resizeBy(new_w,new_h); 
    	win.document.title = img.src.substring(img.src.lastIndexOf("/")+1); 
    	var pic = win.document.getElementById('pic'); 
    	pic.src = img.src; 
    	pic.style.display = 'block'; 
    
    	sw=screen.width; 
    	sh=screen.height; 
    
    	var leftPos=((sw-new_w)/2)-100; // Exactly centered. 
    	var topPos=((sh-new_h)/2)-(vertShift+(((sh-new_h)/2))*0.1); 
    	win.moveTo(leftPos, topPos); 
    }
    Code:
    <a href="../imagepath/image.jpg" target="newwindow" »
    	onclick="imgPop(this.href, this.target); return false;">
    Unfortunately all the images open in the same popup and the popup will not come into focus upon a click. So where would I have to put a focus()-line, so that the popup will come to the front everytime a new link/thumbnail is clicked?

    I appreciate your help.

    Thanks.
    Stefan from Switzerland

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You should specify different target for each image.
    Code:
    <a href="../imagepath/image.jpg" target="newwindow" ..>
    Regarding the focus...
    The popup is already coded to be set focused onload. What browser are you using? It might be going to the else block. Try changing that line to:
    Code:
    else {
      var w = window.open(imageURL, imageTarget);
      w.focus();
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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