1

ポップアップウィンドウに画像を表示する非常にシンプルなページがあります。onLoadイベントは、クエリ文字列を取得し、画像タグにその値を入力してから、画像とウィンドウのサイズを変更して一致させます。

何らかの理由で、これはページがリロード/更新されたときにのみ機能します。または、画像を一度表示すると、キャッシュがオフになっていても、それ以降は機能します。ただし、画像を初めて表示するときはいつでも、エラーがスローされることなくページが空白になります。

助言がありますか?

ありがとう

<!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');
}
4

3 に答える 3

1

ページのロード中に JavaScript を使用して IMG タグを動的に記述し、オンロード時にウィンドウのサイズを変更します。

<!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 sizeWindow() {

      //find the image control
      var img = document.getElementById('dynamicImage');

      //set the window to be just larger than the image
      window.resizeTo(img.width + 50, img.height + 50);
    }
  </script>
</head>
<body onload="sizeWindow();">
  <script type="text/javascript">
    var filename = window.location.search.substring(1);
    document.write("<img src='../Images/" + filename + "' id='dynamicImage' alt='Image Zoom' />");
  </script>
</body>
</html>
于 2010-01-07T18:14:30.567 に答える
0

<img>のSRCを最初に何かに設定する必要があります。何も表示したくない場合は、1x1 ピクセルの透過 GIF を使用してください。

于 2010-01-07T17:10:45.737 に答える
0

本体の onload ではなく、ウィンドウの onload イベントに getImage 関数をバインドしようとしましたか?

于 2010-01-07T18:51:03.520 に答える