You are here: HomeForums » Javascript » Tips and tricks » Check to make sure a page has fully loaded first before printing it

Check to make sure a page has fully loaded first before printing it (1 post)

in Forums » Javascript » Tips and tricks
  • Started 1 month ago by thdadmin

thdadmin (administrator)

The following javscript code helps you determine if the page you are trying to print has loaded completely. This prevents users from printing partialy loaded pages. This problem occurs when a visitor tries to print a page and a page suitable for printing is generated by the browser.
This is the button that upon click prints the page:

<form name="xform"><input type="button" value="print"
	onclick="self.print()"></form>

This is the code that check to see if the page has loaded:

<html>
<head>
<script language="javascript">
    var doneloading = false;
    function printpage()
    {
       if(doneloading)
       {
          window.print();
       }
       else
       {
          alert('page is not done loading yet! please wait and try again.')
       }
    }

    function finishloading()
    {
       doneloading=true;
    }
    </script>
</head>
<body>
.. ...
<a href="printpage()"><img alt="print page"
	src="images/button-image.gif" border="0"></a>
</body>
</html>
... ..
Posted 1 month ago #

Reply

You must log in to post.