admin管理员组文章数量:1416651
I'm trying to print the page in landscape format through javascript. I've found some solutions at Landscape printing from HTML, but those don't fit my need.
The CSS snippet @media print{@page {size: landscape}}
works fine, but I'm not sure how to make it work from javascript/jquery. The reason I'm trying to do this through javascript is because I want 2 buttons for printing. One normal print button which will print the content like it's displayed, and a second button which changes the page a bit and prints it landscape mode.
So in short: I want to change the page orientation (or size as it's called in CSS) to landscape in javascript but the javascript rotation won't do because it also rotates the text on the page. Is there a way to achieve what I'm trying to do without making a separate page using a different layout/CSS?
Thanks in advance.
I'm trying to print the page in landscape format through javascript. I've found some solutions at Landscape printing from HTML, but those don't fit my need.
The CSS snippet @media print{@page {size: landscape}}
works fine, but I'm not sure how to make it work from javascript/jquery. The reason I'm trying to do this through javascript is because I want 2 buttons for printing. One normal print button which will print the content like it's displayed, and a second button which changes the page a bit and prints it landscape mode.
So in short: I want to change the page orientation (or size as it's called in CSS) to landscape in javascript but the javascript rotation won't do because it also rotates the text on the page. Is there a way to achieve what I'm trying to do without making a separate page using a different layout/CSS?
Thanks in advance.
Share Improve this question edited May 23, 2017 at 12:27 CommunityBot 11 silver badge asked Sep 28, 2012 at 14:56 IliansIlians 7437 silver badges23 bronze badges1 Answer
Reset to default 4You can move that rule on another stylesheet and add it dynamically on click:
$("#printLandscape").on('click',function () {
$('head').append('<link href="printLandscape.css" title="printLandscape" rel="stylesheet" />');
});
I've supposed that your "print in landscape mode" button has a printLandscape
id.
Now, to be sure that the user will be able to print in normal mode even after the button is clicked the first time, you can add another listener to the "print in normal mode" button:
$("#printNormal").on('click',function () {
$('link[title="printLandscape"]').attr('disabled', 'disabled').remove();
});
To do this, you must set a title
to the landscape stylesheet (in this case i called it printLandscape
)
本文标签: jquerySet page landscape through javascriptStack Overflow
版权声明:本文标题:jquery - Set page landscape through javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745255339a2650065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论