弹出窗口图像链接和css文件

Popupwindow image link and to css file

本文关键字:css 文件 链接 图像 窗口      更新时间:2023-09-26

如何将图像放在弹出窗口上并链接到CSS文件?假设我想在我的计算机上插入一个名为big.jpg的图像。这可以通过简单的Javascript代码完成吗?

popupWindow.document.writeln('<html><head>');
popupWindow.document.writeln('<link rel="stylesheet" type="text/css" href="tressider.css" />');
popupWindow.document.writeln('</head><body>');
popupWindow.document.writeln('<h2 class="pp">'+help[3].office+'</h2>');
popupWindow.document.writeln('<p></p>');
popupWindow.document.writeln('<h3 >'+'725-0911'+'</h3>');
popupWindow.document.writeln('<p></p>');
popupWindow.document.writeln('<div class="wocao">'+help[3].Description+'</div>');
popupWindow.document.writeln('</body></html>');
popupWindow.document.bgColor="White";
popupWindow.focus();
popupWindow.document.close();

是的,这可以通过直接向窗口中添加样式和img元素来轻松完成。

只需使用:

var _image = popupWindow.document.createElement('img');
_image.setAttribute('width',#);
_image.setAttribute('height',#);
_image.setAttribute('src',"myimg.png");

popupWindow.document.appendChild(_image);

对样式标签也执行同样的操作。

var _style = popupWindow.document.createElement('img');
_style.setAttribute('src',"mystyle.css");
popupWindow.document.appendChild(_style);