Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  14] [ 3]  / answers: 1 / hits: 18820  / 11 Years ago, wed, august 28, 2013, 12:00:00
<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 to access property 'print' @ http://localhost/pdf/print.php:3


i have verified with lot of stack suggested threads for print iframe content. but for me those are not worked.



Exactly above code only present in my print.php file. i want to print the iframe content.



Also i want to know, how to print the specific div which is present inside the iframe. example in this iframe class = 'example_code notranslate' .


More From » jquery

 Answers
35

You can print a cross-domain iframe page perfectly by nesting the cross domain iframe in a locally hosted iframe. A proxy iframe.



This way the parent javascript can print the proxy iframe without issue since it's local, which will transitively print it's inner iframe originating from another domain.



This technique works and has been verified by myself.



In your container page, host the iframe like this



 <iframe id=printf name=printf class=A4 src=/SomeController/IFrameProxy?url=TARGETURL></iframe>


The proxy iframe should look like something like 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 that prints the iframe (defined on container page) should look something like this:



        function printFrame() {
var frm = document.getElementById(printf).contentWindow;
frm.focus();// focus on contentWindow is needed on some ie versions
frm.print();
}

[#76072] Tuesday, August 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
domeniccolti

Total Points: 276
Total Questions: 98
Total Answers: 93

Location: India
Member since Fri, May 13, 2022
2 Years ago
domeniccolti questions
Mon, Oct 18, 21, 00:00, 3 Years ago
Thu, Oct 14, 21, 00:00, 3 Years ago
Thu, Jul 15, 21, 00:00, 3 Years ago
Sat, Oct 24, 20, 00:00, 4 Years ago
Thu, Sep 3, 20, 00:00, 4 Years ago
;