JavaScript 如何打印当前窗口的内容

JavaScript 如何打印当前窗口的内容

任务是通过在文档中使用< strong>window.print()方法来打印当前窗口的内容。它用于打开打印对话框以打印当前文档。它没有任何参数值。

语法:

window.print()

参数: 不需要任何参数

返回值: 该函数不返回任何内容

示例: 这个示例演示了如何使用JavaScript打印当前窗口的内容。

<h1>Hello GeeksForGeeks Users</h1> 
  
<h3> 
    Print the content of the current 
    window using HTML and JavaScript 
</h3> 
  
<form> 
    <input type="button" value="Print" onclick="print_current_page()" /> 
</form> 
  
<script type="text/javascript"> 
    function print_current_page() { 
        window.print(); 
    } 
</script>

输出:

JavaScript 如何打印当前窗口的内容

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程