Javascript DOM onbeforeprint Event via HTML Tag onbeforeprint attribute

Introduction

In HTML:

View in separate window

<!DOCTYPE html>
<html>
<body onbeforeprint="myFunction()">

<p>This example demonstrates how to assign an "onbeforeprint" event to a body element.</p>

<p id="demo"></p>



<h1>Try to print this document</h1>
<script>
function myFunction() {//from  w w w  .j  a v a  2 s.co  m
  document.getElementById("demo").innerHTML = "You are about to print this document!";
}
</script>

</body>
</html>

The onbeforeprint event is not supported in Safari and Opera.

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <body>



PreviousNext

Related