Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sohelrana820/2b1a121c6f0924008700413baf8d01a0 to your computer and use it in GitHub Desktop.
Print an external page without opening it
<!doctype html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MDN Example</title>
<script type="text/javascript">
function closePrint () {
function setPrint () {
this.contentWindow.__container__ = this;
this.contentWindow.onbeforeunload = closePrint;
this.contentWindow.onafterprint = closePrint;
this.contentWindow.focus(); // Required for IE
function printPage (sURL) {
var oHiddFrame = document.createElement("iframe");
oHiddFrame.onload = setPrint; = "hidden"; = "fixed"; = "0"; = "0";
oHiddFrame.src = sURL;
<p><span onclick="printPage('externalPage.html');" style="cursor:pointer;text-decoration:underline;color:#0000ff;">Print external page!</span></p>
Copy link

Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
at HTMLIFrameElement.setPrint (file:///D:/implement/iframe/index.html:12:36)

I want to know why this error has been occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment