我有一個相當簡單的頁面,它在彈出窗口中顯示圖像。 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