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

也许尝试这样的事情:

// 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 回答
0

红色和白色 X 框可能表示您指定的图像源不正确。您是否尝试将您的相对 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 回答