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

标签 javascript html css

如何将图像放在弹出窗口中并将其链接到 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/

相关文章:

javascript - 在 AngularJS 中处理大型数据集

javascript - Angular 和 Firefox 告诉我 OAuth 调用的响应是错误的,Fiddler 告诉我否则

javascript - 使用 jQuery、Ajax、MySQL 和 Java 进行用户身份验证

CSS 仅删除 iframe 的滚动条

html - 获取底部 div 以保持低于位置绝对 div

javascript - 在剑道自动完成中获取选定的对象

javascript - 阻止 javascript 原型(prototype)设计杀死 for 循环

javascript - 如何在 React 中渲染条件 HTML 元素

html - 下拉菜单的外观在不同的屏幕尺寸下是不同的

html - 父级父级的百分比宽度