13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The following is the code required for my first solution (the simpler one of adding a second print button for each section).<br />

It’s in the addPrintLinks function (additions shown in bold):<br />

var btId = "printbut_" + el[i].id;<br />

newLink.setAttribute("id",btId)<br />

newLink.appendChild(newLinkText);<br />

newLink.setAttribute("href","#");<br />

newLinkPara.appendChild(newLink);<br />

//set up the print all link<br />

newLink2.setAttribute("href","#");<br />

var bt2Id = "printall_" + el[i].id;<br />

newLink2.setAttribute("id",bt2Id);<br />

newLink2.appendChild(newLinkText2);<br />

newLink2.setAttribute("href","#");<br />

newLinkPara.appendChild(newLink2);<br />

//add the behaviors for the new links<br />

newLink.onclick = togglePrintDisplay;<br />

newLink.onkeypress = togglePrintDisplay;<br />

newLink2.onclick = printAll;<br />

newLink2.onkeypress = printAll;<br />

Note that the new links will call a new function named printAll. This is a variation of the togglePrintDisplay function<br />

(I copied, pasted, and amended it accordingly). This function simply runs through all the printable sections and resets the<br />

display so that they are visible for print purposes:<br />

function printAll(e)<br />

{<br />

var el = document.getElementsByTagName("div");<br />

for (i=0;i

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

Saved successfully!

Ooh no, something went wrong!