javascript - How do print specific content inside the iframe -
<script type="text/javascript"> function printdoc() { document.getelementbyid("frame_singlecheque").contentwindow.print(); } </script> <iframe style ="height:400px; width: 750px; overflow:scroll;" id="frame_singlecheque" src="http://www.w3schools.com"></iframe> <input type="button" id = "btncprint" value = "print" onclick="javascript:printdoc()" />
error
[16:41:44.054] error: permission denied access property 'print' @ http://localhost/pdf/print.php:3
i have verified lot of stack suggested threads print iframe content. me not worked.
exactly above code present in print.php file. want print iframe content.
also want know, how print specific div present inside iframe. example in iframe " class = 'example_code notranslate' " .
you can print cross-domain iframe page nesting cross domain iframe in locally hosted iframe. "proxy iframe".
this way parent javascript can print proxy iframe without issue since it's local, transitively print it's inner iframe originating domain.
this technique works , has been verified myself.
in container page, host iframe this
<iframe id="printf" name="printf" class="a4" src="/somecontroller/iframeproxy?url=targeturl"></iframe>
the proxy iframe should this
@model string <html> <head> <title>iframe proxy</title> <style> html, body, iframe { height: 100%; width: 100%; margin: 0; padding: 0; border-style: none; } </style> </head> <body> <iframe src="@model" seamless></iframe> </body> </html>
the javascript prints iframe (defined on container page) should this:
function printframe() { var frm = document.getelementbyid("printf").contentwindow; frm.focus();// focus on contentwindow needed on ie versions frm.print(); }
Comments
Post a Comment