1

I was trying to set the print orientation into landscape through javascript. I'm only just using the window.print() function for the page's content to be printed. here's the code:

<a href="" onClick="window.print();return false">
<img src="images/print.png"></a>

With this I was able to print a sample page. But only it was on portrait format. The client requires it to be in landscape. so I tried on many codes I found. here's the one am sure your most familiar with.

<script type="text/javascript">
$("#printLandscape").on('click',function () {
$('head').append('<link href="printLandscape.css" title="printLandscape" rel="stylesheet" />');
});
</script>

since it wasn't a button that am using to call the print function but an image type with href, I tried to change the previous one with:

<a href="" onClick="window.print();return false" id="printLandscape">
<img src="images/print.png"></a>

See the id="printLandscape", I tried that on to be able to call the javascript function declared above and make the page print into my desired format which is landscape. But when I tried to print, to see if it was working. The printed page still has the default/formal or portrait type.

Is there something am missing? Or did I not declare the javascript properly especially the id on href for it not to work fine?

S.O.S

MoonPrincess
  • 75
  • 1
  • 1
  • 10

1 Answers1

5

I think you should make the page property landscape in CSS:

@media print{@page {size: landscape}}

The support is left to the browser and it appears not to be supported in all browsers.