1. Computing

Print This Web Page Code

Let Your Pages Be Printed With a Button

By

Start copying this template below. You may have to copy and paste the code in two sections if there is a commercial in the way. You don't want to copy and paste the commercial and the code around it. Then paste the HTML code in your HTML editor.

About this Template

See What This Page Looks Like

Remember: There are 3 parts to this script.

1. Put This Code In The HEAD of Your Page. Start copying here:

<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function

function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';

if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}

html += '\n</HE>\n<BODY>\n';

var printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}

html += '\n</BO>\n</HT>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
}
}

</script>


-------------------------------------------------------------------------------

2. Put This Part In the BODY of Your Page. You need to put the part of the page you want to have printed inside this code. Start copying this part here:

<div id="printReady">
This text here is inside the div code so when you click on the button this is what will print. The other text above will not. This way you will be able to put into your Web pages what you think your readers will want to print and leave out what you think they won't want to print.
</div>


3. Here are two ways you can place the link on your page for people to click on so they can print the page.

This is the text:


<a href="javascript:void(printSpecial())">Print this Page</a>

Here is the button:

<form id="printMe" name="printMe"> <input type="button" name="printMe" onClick="printSpecial()" value="Print this Page"> </form>

Related Video
Adobe Photoshop Web Button
iMovie Export for Web

©2014 About.com. All rights reserved.