Is there a way to print any given content block on a page? For example if I have 4 content blocks on a page, and have a print button next to each one, clicking on any given print button will print the associated content block?
Thanks
[SOLVED]How to print out individual content blocks
[SOLVED]How to print out individual content blocks
Last edited by blackhawk on Mon Apr 22, 2013 1:35 am, edited 1 time in total.
Re: How to print out individual content blocks
Anyway to do it with global content blocks?
-
- Power Poster
- Posts: 265
- Joined: Mon Mar 14, 2011 1:16 am
Re: How to print out individual content blocks
Wrap each content block in a DIV with a unique ID. For example:
Repeat for all other content blocks, obviously changing the number from '1' to 2, 3, 4 etc.
Then use Javascript to grab the contents of just that DIV, using the element's ID, and print it. Example:
Note: Untested.
Code: Select all
<div id="content-block-1">
{content}
</div>
Then use Javascript to grab the contents of just that DIV, using the element's ID, and print it. Example:
Code: Select all
<__html>
<head>
<__script__ type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" > </__script>
<__script__ type="text/javascript">
function PrintElem(elem) {
Popup($(elem).text());
}
function Popup(data) {
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<__html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head></__body >');
mywindow.document.write(data);
mywindow.document.write('<__body></__html>');
mywindow.document.close();
mywindow.print();
return true;
}
</__script>
</head>
</__body>
<div id="content-block-1">
{content}
</div>
<input type="button" value="Print Content Block 1" onclick="PrintElem('#content-block-1')" />
<a href="javascript:void(0)" onclick="PrintElem('#content-block-1')" />Another way to call the print dialog</a>
<__body>
</__html>
Re: How to print out individual content blocks
Thank you very much for this creative idea!
-
- Power Poster
- Posts: 265
- Joined: Mon Mar 14, 2011 1:16 am
Re: [SOLVED]How to print out individual content blocks
Glad I could help!