jquery - Set page landscape through javascript - Stack Overflow

I'm trying to print the page in landscape format through javascript. I've found some solution

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 badges
Add a ment  | 

1 Answer 1

Reset to default 4

You 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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745255339a4618920.html

相关推荐

  • jquery - Set page landscape through javascript - Stack Overflow

    I'm trying to print the page in landscape format through javascript. I've found some solution

    1小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信