...

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



Hosko
03-17-2005, 03:34 AM
I'm using the following popup-script


/*******************************************************
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);
}


<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

glenngv
03-17-2005, 04:19 AM
You should specify different target for each image.

<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:

else {
var w = window.open(imageURL, imageTarget);
w.focus();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum