Click to See Complete Forum and Search --> : Open new window with image size


esapo
02-17-2003, 10:44 PM
Hi! I need to opne an image in a new window. To do that, I use the following function:

function openNewWindow(url) {
window.open(url,"", 'width=0,height=0');
}

What do I have to add to the code to open the window with the size of the image? I mean, if the image size is 200*300, the width value has to be 200 and height 300

Thanks in advance,

dawgbone
02-17-2003, 11:23 PM
this works as well...

<body>

<script>

function Start(page)
{
openWindow=this.open(page, 'popUpWindow', 'width= 200, height=300, resizable=yes, toolbar=yes, location=yes, status=yes, menubar=yes, copyhistory=yes');

//the last few will take away things like the tool bar and that...
}

</script>

Click on the image to see a larger image:<br>
<a href='javascript:Start("bigImage1.html");'><img src='image name' border='0'></a>

//you just click on the thumbnail to make it bigger.

</body>

LAwebTek
02-17-2003, 11:57 PM
I think that this may be closer to what you are looking for:

<html>
<head>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">

function getImage(img) {
var wide, high
pic = new Image()
pic.src = (img)
viewImage(img)
}

function viewImage(img) {
wide = pic.width + 20
high = pic.height + 20
wh = "width=" + wide + ",height=" + high
window.open(img,'',wh);
}
</script>
</head>

<body>
<A HREF="javascript:getImage('sample.gif')"><img src="sample.gif" border="0" width="155" height="132"></A>
</body>
</html>

LAwebTek

Charles
02-18-2003, 05:01 AM
That will give you a link that does nothing at all for the one in ten users that do not use JavaScript and the countless users who have disabled pop-ups. And it will open an itty-bitty window on Opera even if the user is using JavaScript and allowing pop-ups. The following corrects for those problems:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
function imageWin (url) {
var pic = new Image();
pic.src = url;
if (pic.height) {
var param = 'height=' + Number(pic.height + 30);
param += ',width=' + Number(pic.width + 20);
}
window.open (url, 'child', param);
return false;
}
// -->
</script>
<a href="http://www.bettiepage.com/images/photos/whip/whip7.jpg" onclick="return imageWin(this.href)"><img alt="[Bettie with a whip.]" src="http://www.bettiepage.com/images/photos/whip/whip7_a.jpg"></a>