13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

hide the sections from printout<br />

el[i].setAttribute("className","print_section noprint");<br />

el[i].setAttribute("class","print_section noprint");<br />

}<br />

}<br />

}<br />

if (window.event)<br />

{<br />

window.event.returnValue = false;<br />

window.event.cancelBubble = true;<br />

}<br />

else if (e)<br />

{<br />

e.stopPropagation();<br />

e.preventDefault();<br />

}<br />

window.print();<br />

}<br />

addEvent(window, 'load', addPrintLinks, false);<br />

What about the CSS?<br />

Wow, with all the talk of scripting, you might have forgotten that there’s another very important aspect to this, and that’s<br />

the print CSS styles. The scripts change the classnames of the various elements in the document, but somewhere we need to<br />

define the appearance of these items. The following CSS needs to be added to the document. The first part is purely cosmetic<br />

(for the link—to make it appear “buttony”), but the important part is highlighted in bold:<br />

.print_section p.printbutton<br />

{<br />

float:left;<br />

}<br />

.print_section p.printbutton a<br />

{<br />

text-decoration:none;<br />

background:white;<br />

display:block;<br />

float:left;<br />

margin:3px;<br />

padding:10px;<br />

border:1px solid red;<br />

}<br />

@media print<br />

{<br />

.noprint, .printbutton<br />

{<br />

display:none;<br />

}<br />

.print<br />

{<br />

display:block;<br />

}<br />

}<br />

chapter 8 Print Magic: Using the DOM and CSS to Save the Planet<br />

197

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!