English 中文(简体)
Javascript - Page Printing
  • 时间:2024-09-17

JavaScript - Page Printing


Previous Page Next Page  

Many times you would pke to place a button on your webpage to print the content of that web page via an actual printer. JavaScript helps you to implement this functionapty using the print function of window object.

The JavaScript print function window.print() prints the current web page when executed. You can call this function directly using the oncpck event as shown in the following example.

Example

Try the following example.

<html>
   <head>      
      <script type = "text/javascript">
         <!--
         //-->
      </script>
   </head>
   
   <body>      
      <form>
         <input type = "button" value = "Print" oncpck = "window.print()" />
      </form>   
   </body>
<html>

Output