Open GoogleCodeExporter opened 8 years ago
Print it's not possible for "content" because there is no <iframe /> tag in
HTML...
Original comment by szczepanski.jaroslaw
on 12 May 2010 at 12:25
You're right !
Original comment by Julien.N...@gmail.com
on 14 May 2010 at 3:32
Original comment by Julien.N...@gmail.com
on 14 May 2010 at 5:03
There actually is a way to print the content of a div. An example can be found
at:
http://stackoverflow.com/questions/468881/print-div-idprintarea-div-only
I tested this in the latest versions of Internet Explorer, Firefox, Opera, and
Google Chrome and it worked consistently in all browsers.
Here is the code:
------------------------------------------------------------------------------
****************************Do not print this.
<br />
<script language="javascript">
var gAutoPrint = true;
function processPrint(oDivObject){
if (document.getElementById != null){
var html = '<HTML>\n<HEAD>\n';
if (document.getElementsByTagName != null){
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0) html += headTags[0].innerHTML;
}
html += '\n</HE' + 'AD>\n<BODY>\n';
var printReadyElem = document.getElementById(oDivObject);
if (printReadyElem != null) html += printReadyElem.innerHTML;
else{
alert("Error, no contents.");
return;
}
html += '\n</BO' + 'DY>\n</HT' + 'ML>';
var printWin = window.open("","processPrint");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint) printWin.print();
} else alert("Browser not supported.");
}
</script>
<div id="oDivContent">
This is the content to print.
</div>
<br />
<a href="javascript:void(processPrint('oDivContent'));">Print</a>
<br />
****************************Do not print this.
------------------------------------------------------------------------------
Original comment by charles....@gmail.com
on 16 Sep 2010 at 11:53
Attachments:
I would also think that rather than displaying content in a div you could
probably display it in the iframe by setting the content of the iframe using
the innerHTML property.
See below:
var myIFrame = document.getElementById(iFrameName);
var content = myIFrame.contentWindow.document.body.innerHTML;
Original comment by charles....@gmail.com
on 17 Sep 2010 at 12:00
Original issue reported on code.google.com by
ricardo....@gmail.com
on 19 Mar 2010 at 4:36Attachments: