Sign Up! Login: Password: New User? Forgot? Support
Top Mods!
Wowhead Search
by sonofsamedi
Digital Clock
by Wolfar15
Admin Forums
Welcome to the GuildPortal Help Community! These forums are for admin-to-admin help.
Available Forums
Mottie (MVP) 5/17/2009 2:41 PM EST : Printing a Forum Post
GuildPortal MVP
Mottie
Posts: 3884
Zomgawsh Poster

Printing a Forum Post

This small jQuery script adds a print button under each forum post. After clicking on this button, a popup window opens with a print & close button. You can set the script to auto print the window, but sadly I didn't get the popup window to auto close after printing without messing up in IE so I left it out 

It's best to add the code below into a free form text/HTML box on your forums page. Anyway, I hope someone out there finds it useful.



The Code
<script type="text/javascript">
var printButtonURL = "http://i201.photobucket.com/albums/aa236/Mottie1/testsite/icons/forum_print.png";
var autoPrint = true;
var popupWidth = 500;
var popupHeight = 500;
$(document).ready(function(){
 var tmp = '<img class="tooltip" style="cursor:pointer;" src="' + printButtonURL +
  '" alt="Print" title="Print this message" onclick="printWin($(this))">';
 $('.MessageToolsCell1').find('div:first').append(tmp);
})
function printWin(el){
 var msg = el.closest('table');
 var msgContent = msg.find('.MessageBodyCell1').html();
 var pgtitle = msg.parent().find('.MessageSubjectCell1').text();
 pgtitle = pgtitle.replace(/(\s\s)/g,'').replace(/(\t)/g,'');
 var tmp = '<html><head><title>Posted ' + pgtitle + '</title><style media=print>.h,.MessageToonContainer1,.MessageSignature';
 tmp += '{display:none;}</style></head><body><div class=h><input onclick=window.print() type=button value=Print>';
 tmp += '<input onclick=window.close() type=button value=Close><hr></div>' + msgContent + '</body></html>';
 var temp = "menubar=yes,location=no,toolbar=0,status=0,scrollbars=1,width=" + popupWidth + ",height=" + popupHeight;
 var w = window.open ('','Print',temp);
 w.document.write(tmp);
 if (autoPrint) w.print();
}
</script>
Customizing
  • Change the print button image by changing replacing the URL in the "printButtonURL" variable in orange.
  • Stop the message from being automatically printed by setting the "autoPrint" variable to false (in blue).
  • Set the popup window width and height (in pixels) by modifing the numbers in red.
Edit (7/8/2009): Updated & fixed the script to realign the print button.
Edit (1/31/2010): Updated the code so the printed page won't show the poster's list of toons or signature.
TopBottom

Guppy Queen (New Admin) 5/18/2009 12:44 PM EST : RE: Printing a Forum Post
Guppy Queen
Posts: 41034
Zomgawsh Poster

Thank you Mottie. This is great!
TopBottom

Mottie (MVP) 7/8/2009 9:03 AM EST : RE: Printing a Forum Post
GuildPortal MVP
Mottie
Posts: 3884
Zomgawsh Poster

Optimized & updated the code to fix the print button alignment
TopBottom

Guppy Queen (New Admin) 7/8/2009 12:20 PM EST : RE: Printing a Forum Post
Guppy Queen
Posts: 41034
Zomgawsh Poster

Thanks Mottie
TopBottom

Mottie (MVP) 2/1/2010 1:04 AM EST : RE: Printing a Forum Post
GuildPortal MVP
Mottie
Posts: 3884
Zomgawsh Poster

Updated so the printed page won't show the poster's list of character names or signature
TopBottom

Admins Online
There are   members online.
So-and-so has logged on!
%title%
%message%