如何将图像放在弹出窗口中并将其链接到 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();
最佳答案
是的,这可以通过直接在窗口中添加 style 和 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);
关于javascript - 弹出窗口图像链接和 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17730651/