我有一个页面,我可以像这样打开一个新窗口
var myWindow = window.open("", "", "width=755.9100,height=347.7200");
myWindow.document.body.append(img);
我想从上一个窗口向这个新窗口添加一些样式
@page {size: A4;margin: 0;@media print {html, body {width: 210mm;height: 297mm;}
如何通过js将此添加到html中的head标签中?
最佳答案
有 window.matchMedia js中的函数:
用法很简单:
if (window.matchMedia("(min-width: 400px)").matches) {
/* the viewport is at least 400 pixels wide */
} else {
/* the viewport is less than 400 pixels wide */
}
一篇更有用的文章是here .
关于javascript - 从 js 添加媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42572840/