PDA

View Full Version : Cross-browser Popup Image Viewer?


entint
06-07-2005, 12:58 PM
Just curious if anyone has a crossbrowser version of the Popup Image Viewer script that's in the Post a JavaScript section. Seems that all of the ones in there (original and modifications) are browser specific, whereas I need something that will work for all browsers, or at least IE and firefox.

vwphillips
06-07-2005, 01:01 PM
http://homepage.ntlworld.com/vwphillips//ImagePopUp/ImagePopUp.htm

entint
06-07-2005, 01:08 PM
That's an unbelievably awesome script. Thanks so much :D

glenngv
06-07-2005, 01:11 PM
http://www.codingforums.com/showthread.php?p=318055#post318055

entint
06-08-2005, 03:05 AM
Hello again glenn. I decided to use the version of beetle's script that you modified, but I'm still having some issues in IE. I know you mentioned an error that you weren't sure why the error was happening, and I am trying to figure out why and see if I can fix it...but the other problem I'm having is that in IE after the window opens, it closes by itself. Any idea as to why this could be happening?


(just to note, it might have to do with my settings in IE because I get this error a lot with other sites as well, but then it usually happens in firefox too)

glenngv
06-08-2005, 03:31 AM
Are you using IE/XP? I'm thinking it's because of different zone (Internet zone on about:blank page and Local Intranet zone on your page). Regarding the other error, I don't have any idea. Try this sample page:
<html>
<head>
<title>Popup Image Viewer</title>
<script type="text/javascript">
function popImg(imageURL) {
var imgWin = window.open('about:blank','imgWin','width=200, height=200, left=100, top=100');

with (imgWin.document) {
writeln('<html><head><title>Loading...</title>');
writeln('<style type="text/css"><!-- body { margin: 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;
return false;
}

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';
}
</script>
</head>
<body>
<a href="test.jpg" onclick="return popImg(this.href);">test</a>
</body>
</html>
Of course, you need to change the href to a valid image. I tested it with IE6/Win2K and Firefox and both worked.

If the first problem persist, then you may resort to creating a dummy page.
var imgWin = window.open('dummy.htm', ...

entint
06-08-2005, 03:56 AM
yeah I'm using IE/XP, and I still get the same problem with the instant window closing on your test page. Doesn't happen in firefox at all. All my internet security settings for IE are set to default, and I'm testing everything on the internet (not locally) so I don't know why it's not working or why I get this error from other pages that use pop-ups as well.

I get two different script errors, but the window doesn't pop up when these appear and this must have something to do with the error that you are unsure about. I get 1) a denied access error in which the line number varies all over the place 2) a error tha reads "The callee (server[not server application]) is not available and has disappeared; all connections are invalid. The call did not execute", and this error usually shows up for these lines of the script:

var old_w = win.innerWidth || win.document.body.offsetWidth;
var old_h = win.innerHeight || win.document.body.offsetHeight;


So it's still giving me issues...do you think that this auto close thing is an issue on my end?

by the way I just tried it again after resetting all my web settings for IE to default, and I'm still getting the error...

entint
06-08-2005, 04:41 AM
Found a new script that not only works in firefox and IE, but works in all major browsers and doesn't give script errors in IE. Thanks for all the help though glenngv. :D

String
08-03-2009, 05:23 PM
Found a new script that not only works in firefox and IE, but works in all major browsers and doesn't give script errors in IE. Thanks for all the help though glenngv. :D

Hi can you share the script or link that works for you. I can't seem to find any.