Javascript DOM onbeforeprint Event via HTML Tag onbeforeprint function

Introduction

In JavaScript:

object.onbeforeprint = function(){
       myScript};

This example uses the HTML DOM to assign an "onbeforeprint" event to a body element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<h1>Try to print this document</h1>
<p id="demo"></p>
<script>
document.getElementsByTagName("BODY")[0].onbeforeprint = function() {myFunction()};

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

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



PreviousNext

Related