GetComputedStyle到屏幕以外的其他媒体
GetComputedStyle to other media than screen
@media screen{
a {color:green}
}
@media print{
a {color:red}
}
是否有一种方法,使用JavaScript,得到"a"元素的颜色,当它被打印?正常的getComputedStyle
只适用于screen
介质
我不想读取style元素。我需要computed style
我开发了一个解决方案,如何删除所有的样式打印媒体。这样,打印样式将与SCREEN样式相同。
这是为了使打印机打印出来的东西和屏幕上显示的一模一样。
console.debug('styleSheetsLength')
$('link[media=print]').remove()
$('link[media*=screen]').attr('media','print,screen')
for (var x=0; x<document.styleSheets.length;x++){
console.groupCollapsed('styleSheet-' + x,document.styleSheets[x])
if(document.styleSheets[x].rules){
for (var i=0; i<document.styleSheets[x].rules.length;i++) {
console.groupCollapsed('rule-(' + x + ')-' +i + document.styleSheets[x].rules[i])
console.debug(document.styleSheets[x].rules[i])
if(document.styleSheets[x].rules[i].media){
for(var j=0;j<document.styleSheets[x].rules[i].media.length;j++){
if (document.styleSheets[x].rules[i].media[j].indexOf('print')>-1)
document.styleSheets[x].rules[i].media.mediaText='nothing'
if (document.styleSheets[x].rules[i].media[j].indexOf('screen')>-1)
document.styleSheets[x].rules[i].media.mediaText='print,screen'
}
}
console.groupEnd();
}
}
console.groupEnd()
}
相关文章:
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 如何添加浮动和非浮动,其他
- 与其他库的jQuery.noConflict()
- 播放当前视频时如何停止其他视频?JavaScript
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 除修剪外的其他功能
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- Array.length似乎不起作用;console.log则显示其他情况
- 如何消除代码中的未定义和其他问题
- 如何覆盖锚点元素's href目标,并在我点击转到目标javascript时删除其他错误
- jquery代码在Mozilla中有效,但在其他浏览器上无效
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- 如何使用cordova在Whatsapp/Facebook/Instagram和任何其他社交媒体上分享图片
- Firefox 和 Chrome 阻止 youtube 视频和其他媒体
- JW播放器-当其他媒体(RTMP)断开连接时,循环MP4待机视频
- GetComputedStyle到屏幕以外的其他媒体
- 社交媒体网站阻止其他网站在iFrame中显示他们的页面
- 其他页面对同一媒体查询没有响应
- 使用媒体查询添加类或其他属性