Javascript Reference - Window print() Method








The print() method opens the Print Dialog Box.

Browser Support

print Yes Yes Yes Yes Yes

Syntax

window.print()

Parameters

None.

Return Value

No return value.

Example

The following code shows how to Print the current page.


<!DOCTYPE html>
<html>
<body>
<!-- ww  w  .j  a v a 2  s. co  m-->
<button onclick="myFunction()">Print this page</button>

<script>
function myFunction() {
    window.print();
}
</script>

</body>
</html>

The code above is rendered as follows: