This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 30th, 2013  |  syntax: None  |  size: 0.42 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var iframe = document.createElement('iframe');
  2.  
  3. iframe.onload = function() {
  4.     var doc = iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document;
  5.     doc.getElementsByTagName('body')[0].innerHTML = "<p>1234</p>";
  6.  
  7.     iframe.contentWindow.focus(); // This is key, the iframe must have focus first
  8.     iframe.contentWindow.print();
  9. }
  10.  
  11. document.getElementsByTagName('body')[0].appendChild(iframe);
clone this paste RAW Paste Data