/

HTML / CSS / JavaScript Tutorial

JavaScript Window method: print()

[this page | pdf | back links]

The print() method (when applied to Window objects in the JavaScript BOM) prints the contents of the window.

 

It has the following syntax with no parameters. It does not return a value.

 

window.print()

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
<button onclick="myOnclick()">Print page</button><br>

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

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodWindowPrint() {
  return !!window.print;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile