In Javascript, DOM object window provides the access to a function called print that allows you to open the window print dialog box to take out the prints of the currently opened web page. Javascript window object refers to the window of web browser displaying the web page. window.print() method calls the printer dialog box that displays the default printer settings and preferences available on the client’s system.
window.print();
Above lower case syntax is used to open the window print dialog box using Javascript code.
<head>
<title>Javascript Window.Print</title>
<style type="text/css">
}
</head>
<a href="javascript:window.print();">Print this page</a>
</html>
You can use the javascript:window.print(); or simply window.print() to open the print dialog box of client’s system. Javascript: prefix is used to overcome the issue of accessing the print function of window object in different web browser and lower to higher versions. You can call the print function through the href attribute value of HTML <a> anchor tag or onclick event of input type button.
By Default window print function retrieves the default page settings for printing as portrait orientation of the page. You can change the orientation to landscape using the preferences button of print dialog. Click on preferences button, it will open the printing preference setup. Select the landscape radio button option of orientation properties to print the web page as landscape. You can also change the Paper Size, Paper Type and Print Quality in the printing preferences of window print dialog box.
Currently rated 2.3 by 3 people
Tags: javascript, dom, javascript window object, javascript print, javascript window.print, javascript print landscape, javascript open window print client side, javascript window.open, learn javascript, javascript examples, javascript window status
10/14/2008 1:06:59 PM