JavaScript / HTML中的对比层

时间:2012-06-20 07:04:05

标签: javascript html5 html contrast

我的网络应用程序的基础是一张地图,由很多苍白的瓷砖组成。 因此,使用黑白打印机打印此页面的结果非常严重。

是否有可能在地图上铺设一些图层,这会使它更具对比度?

(在打印模式下更换瓷砖是一个坏主意,是的。)

1 个答案:

答案 0 :(得分:0)

你有两条路线。首先是添加打印样式表,如下所示:

<link rel="stylesheet" href="printstyle.css" media="print" />

或者,在没有媒体声明的常规css文件中,

@media print { 
    #my-map-element {
        display: none; /* just for an example */
    }
}

另一种方法是在发生打印事件时调用javascript函数。但是,据我所知,这仅受Firefox 6+和IE支持:

window.onbeforeprint = function() { /* ... */ }

如果您是从javascript生成打印事件,则可以使用以下代码解决浏览器兼容性问题:

(function(){

  // make a copy of the native window.print
  var _print = this.print;

  // create a new window.print
  this.print = function () {
    // if `onbeforeprint` exists, call it.
    if (this.onbeforeprint) onbeforeprint(this); 
    // call the original `window.print`.
    _print(); 
    // if `onafterprint` exists, call it.
    if (this.onafterprint) onafterprint(this);
  }

}())

(来源:https://stackoverflow.com/a/3339821/300011

相关问题