Saturday, 23 April 2016

How to print a web page using JS ?


window.print() Function 

Examples
<A HREF="javascript:window.print()" mce_HREF="javascript:window.print()" mce_HREF="javascript:window.print()">Click to Print This Page</A>

<A HREF="javascript:window.print()" mce_HREF="javascript:window.print()"> <IMG SRC="print_image.gif" mce_SRC="print_image.gif" BORDER="0"> </A>

<FORM>
   <INPUT TYPE="button" onClick="window.print()">
</FORM>


To make sure that your visitors have JavaScript enabled before you provide them with a button that only works using JavaScript, you can use JavaScript to print out the button.

That way if they have it disabled, no button appears, saving them the frustration of clicking a button that does absolutely nothing :
<SCRIPT LANGUAGE="JavaScript">
 if (window.print) {
   document.write('<form> <input type=button name=print value="Print" onClick="window.print()"> </form>');
 }
</SCRIPT>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.