由于ie8兼容模式的特殊css,如何使用JavaScript为媒体打印编写css?

时间:2023-02-13 15:06:51

I am setting up some css for @media print and I had to make use of IE conditionals to get it cross-browser compatible. Looking here and elsewhere, it seems there's no IE conditionals that detect IE 8 compatibility mode. The only way to do so is make use of meta tags or JavaScript, correct?

我正在为@media打印设置一些css,我不得不使用IE条件来使其跨浏览器兼容。在这里和其他地方看来,似乎没有IE条件检测到IE 8兼容模式。唯一的方法是使用元标记或JavaScript,对吗?

I know how to detect compatibility mode in JavaScript. My question is how do I write one particular line of css for @media print using JavaScript. If i have to, I'll settle for linking to a separate stylesheet. But I managed to get my current print media stylesheet cross-browser compatible, with the notable exception of ie 8 compatibility mode. If I can just add what I need in JavaScript, instead of creating a separate stylesheet for IE 8 compatibility mode, that would be great. Either way, I would like to know how I can add @media print css for IE 8 compatibility mode using Javascript?

我知道如何在JavaScript中检测兼容模式。我的问题是如何使用JavaScript为@media print编写一个特定的css行。如果必须,我将决定链接到单独的样式表。但我设法让我当前的打印媒体样式表跨浏览器兼容,除了ie 8兼容模式之外的明显例外。如果我可以在JavaScript中添加我需要的内容,而不是为IE 8兼容模式创建单独的样式表,那就太棒了。无论哪种方式,我想知道如何使用Javascript为IE 8兼容模式添加@media print css?

Thank you!

谢谢!

1 个解决方案

#1


0  

Have you tried just to add inline style tag:

您是否尝试过添加内联样式标记:

var sheet = document.createElement('style')
sheet.innerHTML = "[your media query here]";
document.body.appendChild(sheet);

#1


0  

Have you tried just to add inline style tag:

您是否尝试过添加内联样式标记:

var sheet = document.createElement('style')
sheet.innerHTML = "[your media query here]";
document.body.appendChild(sheet);