Skip to content

Instantly share code, notes, and snippets.

@zgordon
Created April 7, 2011 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgordon/907626 to your computer and use it in GitHub Desktop.
Save zgordon/907626 to your computer and use it in GitHub Desktop.
Pure JavaScript model of how to build and add to screen a working print button
window.onload = function()
{
if(!document.getElementsByTagName) return false;
var print = document.createElement("a");
print.href = "#"; print.id = "printlink";
var print_icon = document.createElement("img");
print_icon.src = ("printer.png");
var print_link_node = document.createTextNode("print");
print.appendChild(print_icon);
var notice = document.getElementById("notice");
notice.appendChild(print);
print_link = document.getElementById("printlink");
print_link.onclick = function() { window.print(); }
function insertAfter(referenceNode, newNode){ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling ); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment