0

私はHTMLとjavascriptを学んでいますが、何かをうまく動かすことができません:

作成中の新しいページがあり、その上に画像を表示したい:

thepage= window.open('', '', 'height=700,width=800,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');

ページがフォーカスされると表示されますが、そこに画像を配置しようとすると、せいぜい赤と白の x ボックスしか表示されません。

私が試してみました:

thepage.document.write(<img src=".\Images\theImage.jpg")

しかし、画像コードが機能するメインページやその他のさまざまなものと同じであっても、これは機能しません。

画像のみを表示するポップアップではなく、メインページと同じ画像を含む新しいページが必要であることに注意してください(少なくとも最初は)。

当たり前だと分かっていても、ここの木には木が見えないところまで来てしまった!!

4

3 に答える 3

0

赤と白のXボックスは、指定している画像ソースが正しくないことを意味している可能性があります。相対URLを固定URLに変更してみましたか?

代わりに.\Images\theImage.jpg、完全な画像URLを提供する方が常に安全です。

于 2013-01-21T14:23:32.503 に答える
0

さて、引用符が間違った場所にあるというタイプミスがありますが、次のようにしてみてください。

var thepage = window.open('', '', 'height=700,width=800,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
thepage.document.body.appendChild("<img src=\".\Images\theImage.jpg\">");

画像の位置が正しいことを確認してください。/Images/theImage.jpg

于 2013-01-21T14:27:27.170 に答える
0

たぶん、次のようなことを試してください:

// open your new window
var theArena = window.open('', '', 'height=700,width=800,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');

// create a base tag, and set the HREF to the same as your current page.
// This should allow you to use relative URLs for images and links
var base = theArena.document.createElement('base');
base.href = document.location.href
theArena.document.body.appendChild(base);

// Now use createElement to build the element
var img = theArena.document.createElement('img');
img.src = "./Images/theImage.jpg"; // make sure the URL is valid
theArena.document.body.appendChild(img);
于 2013-01-21T14:32:40.367 に答える