使用 jquery 更改打印样式(横向、纵向)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16805257/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:50:10  来源:igfitidea点击:

Change print style (landscape , portrait) using jquery

javascriptjqueryhtmlcssprinting

提问by user1871516

Currently I have create 2 css file , to simplify : the main difference between them are:

目前我创建了 2 个 css 文件,以简化:它们之间的主要区别是:

print.css

打印文件

@page {
  size: landscape;
}

print_single.css

print_single.css

@page {
  size: portrait;
}

For the html file , it quote one of the css first

对于 html 文件,它首先引用其中一个 css

<link rel="stylesheet" id ="printCSS" href="css/print.css" type="text/css" media="print" />

Then if it is printing single page , I use jquery to change the path of the css file, otherwise , it will print in landscape :

然后如果它是打印单页,我使用jquery更改css文件的路径,否则,它将以横向打印:

    $(doc).ready(function(){
      $('#singlePrint').click(function(){
      $('#printCSS').attr('href','css/print_single.css');
    });    
});

The problem is , it seems only work in Chrome, I tried it on firefox and ie, the css file path is changed, but the css file is not reload , how to fix the problem ? thanks.

问题是,它似乎只能在 Chrome 中工作,我在 firefox 上尝试过,即更改了 css 文件路径,但未重新加载 css 文件,如何解决问题?谢谢。

回答by Anna.P

@page{size: landscape;} will not support in firefox. Alternative way is to use this in css class

@page{size: Landscape;} 在 Firefox 中不支持。另一种方法是在 css 类中使用它

-webkit-transform: rotate(-90deg); -moz-transform:rotate(-90deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);