javascript window.open 样式使用 css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21224676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.open Style using css
提问by Getsomepeaches
I would like to style my window.open,
我想设计我的 window.open,
I currently have some items on my webpage that open due to a certain class that is parsed, which there after opens the specified text in a new window.
我目前在我的网页上有一些项目由于解析了某个类而打开,然后在新窗口中打开指定的文本。
I would like to change the font-size, font and padding etc.
我想更改字体大小、字体和填充等。
Here is my javascript code.
这是我的 javascript 代码。
<script type="text/javascript">
$(".Show a").click(function () {
var html = $(this).parent().next("div.show-dialog").html();
var my_window = window.open("", "mywindow1", "width=750,height=550");
$(my_window.document).find("body").html(html);
});
</script>
How do I parse css styles in javascript?
如何在 javascript 中解析 css 样式?
回答by mattdlockyer
Check out this answer: https://stackoverflow.com/a/18758370/1060487
看看这个答案:https: //stackoverflow.com/a/18758370/1060487
From the answer:
从答案:
Build a complete HTML page in the opened window and reference your CSS-file there:
在打开的窗口中构建一个完整的 HTML 页面并在那里引用您的 CSS 文件:
var win = window.open('','printwindow');
win.document.write('<html><head><title>Print it!</title><link rel="stylesheet" type="text/css" href="styles.css"></head><body>');
win.document.write($("#content").html());
win.document.write('</body></html>');
win.print();
win.close();