Print Selectable Area Of HTML

Started on the old forum in May 2009 · view the original in the archive · old links redirect here

No replies · 547 views · started 17 years ago · 1 min read

synergyx2009 Developer · 86 posts #1

This script can be used to print an ary you have selected:

ADD FOLLOWING SCRIPT TO BODY:

<script type="text/javascript">
<!--
function printContent(ID)
	{
	str=document.getElementById(ID).innerHTML
	newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
	newwin.document.write('<HTML>\n<HEAD>\n')
	newwin.document.write('<TITLE>ANY TITLE HERE</TITLE>\n')
	newwin.document.write('<script>\n')
	newwin.document.write('function chkstate(){\n')
	newwin.document.write('if(document.readyState=="complete"){\n')
	newwin.document.write('window.close()\n')
	newwin.document.write('}\n')
	newwin.document.write('else{\n')
	newwin.document.write('setTimeout("chkstate()",2000)\n')
	newwin.document.write('}\n')
	newwin.document.write('}\n')
	newwin.document.write('function print_win(){\n')
	newwin.document.write('window.print();\n')
	newwin.document.write('chkstate();\n')
	newwin.document.write('}\n')
	newwin.document.write('<\/script>\n')
	newwin.document.write('</HEAD>\n')
	newwin.document.write('<BODY onload="print_win()">\n')
	newwin.document.write(str)
	newwin.document.write('</BODY>\n')
	newwin.document.write('</HTML>\n')
	newwin.document.close()
	}
//-->
</script>

ADD PRINT BUTTON:

<input type=button value="Print this Page" name="Print" onClick="printContent('print_content');">

WRAP CONTENT THAT YOU WANT TO PRINT AROUNT THESE DIV TAGS:

<div id="print_content">
content you want to print
</div>

|Dont forget to say thanx|

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close