我有一个相当简单的页面,它在弹出窗口中显示图像。 onLoad事件只需要查询字符串,使用该值填充图像标记,然后调整图像和窗口的大小以匹配。JavaScript只在页面重新加载时起作用
出于某种原因,这只适用于页面重新加载/刷新时。或者,一旦图像被显示一次,即使缓存关闭,它也将从此工作。但是,无论何时第一次查看图像,页面都会显示为空白,并且不会引发错误。
有什么建议吗?
感谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Image Zoom</title>
<meta http-equiv="Pragma" content="no-cache" />
<script type="text/javascript">
function getImage() {
//get the query string (everything after the ?)
var filename = window.location.search.substring(1);
//find the image control
var imageWorking = document.getElementById('dynamicImage');
//assign the image source
imageWorking.src = '../Images/' + filename;
//create an image variable
var newImg = new Image();
//assign the source to match the page image
newImg.src = imageWorking.src;
//get the width and height
var width = newImg.width;
var height = newImg.height;
//set the page image width and height to match the disk image
imageWorking.width = width;
imageWorking.height = height;
//set the window to be just larger than the image
window.resizeTo(width + 50,height + 50);
}
</script>
</head>
<body onload="getImage();">
<img src="images/spacer.gif" id="dynamicImage" alt="Image Zoom" width="1" height="1" />
</body>
</html>
该页面使用下面的函数调用:
function imageZoom(imageName)
{
window.open('ImageZoom.htm?' + imageName + '','imageZoom','width=400,height=400,menubar=no,toobar=no,scrollbars=yes,resizable=yes');
}
你刚刚从你的硬盘上运行这个?你从网络服务器上试过了吗? – 2010-01-07 17:11:03
还没有尝试从网络服务器。这是针对CHM帮助应用程序的,因此它将始终从硬盘驱动器运行。 – Brad 2010-01-07 17:46:48
尝试在'.hta'文件中运行它。 – 2010-01-07 18:50:38