As an example of gracefully degrading, here's a script I'm playing around with now:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Selective Print Demo</title>
<!-- Begin Selective Print Styles -->
<style type="text/css">
#printarea {display: none;}
</style>
<style type="text/css" title="copyprint" media="print">
#screencontent {display: none;}
#printarea {display: block;}
</style>
<noscript>
<style type="text/css" media="print">
#screencontent {display: block;}
#printarea {display: none;}
</style>
<style type="text/css">
.print {display: none;}
</style>
</noscript>
<!-- End Selective Print Styles -->
<script type="text/javascript">
// Selective Print Script (c)2013 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/
// username: jscheuer1 - This Notice Must Remain for Legal Use
(function(){
var sheets = document.getElementsByTagName('style'), i = sheets.length, printsheet;
while(--i > -1){
if (sheets[i].title === 'copyprint'){
printsheet = sheets[i];
printsheet.disabled = true;
}
}
function copyPrint(element){ //function used to copy print the innerHTML of the passed in element
var savedtitle = document.title;
element = element.tagName? element : document.getElementById(element);
document.getElementById('printarea').innerHTML = element.innerHTML;
document.title = element.getAttribute('data-print-title') || savedtitle;
printsheet.disabled = false;
window.print();
document.getElementById('printarea').innerHTML = '';
document.title = savedtitle;
printsheet.disabled = true;
}
function printbuttons(e){
e = e || event;
var t = e.target || e.srcElement;
if(t.type === 'button' && t.value === 'Print'){
copyPrint(t.getAttribute('data-printid'));
}
}
if (document.addEventListener){
document.addEventListener('click', printbuttons, false);
}
else if (document.attachEvent){
document.attachEvent('onclick', printbuttons);
}
})();
</script>
</head>
<body>
<div id="printarea"></div>
<div id="screencontent">
<input class="print" type="button" value="Print" data-printid="print" />
<div id="print" data-print-title="List One">
<ul>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>
<input class="print" type="button" value="Print" data-printid="print1" />
<div id="print1" data-print-title="List Two">
<ul>
<li>11</li>
<li>11</li>
<li>11</li>
</ul>
</div></div>
</body>
</html>
It allows you to selectively print one or the other of the two lists. If javascript is unavailable, the print buttons are not seen and the entire page may be printed normally. Even with javascript, if the user chooses to print the entire page in the normal way, the entire page may be printed. At least that's the idea. Demo:
http://home.comcast.net/~jscheuer1/s...ntcontent3.htm
Bookmarks