【发布时间】:2018-07-24 23:57:55
【问题描述】:
我必须打印iframe 中的特定文件。
我的 view_file.ejs:
<div id="viewframe">
<iframe id="viewfile" name="viewfile" src='https://docs.google.com/viewer?url=<%= urlencode.encode(img) %>&embedded=true' style="width: 100%;height:900px" frameborder="0" scrolling="no" seamless="" allowfullscreen="allowfullscreen">
</iframe>
</div>
这里的 img(这是我在 urlencode.encode 中使用的变量)是来自 aws s3 存储桶的链接
打印按钮:
<div class="right_blk">
<span class="versions"><a ng-click="printdoc('viewframe')" href="javascript:void(0)" >Print</a></span>
</div>
我的 app.js:
$scope.printdoc1=function(doc)
{
window.frames["viewfile"].focus();
window.frames["viewfile"].print();
}
我从这里尝试了许多解决方案,但对我没有任何作用。有什么办法吗?
更新
core.js:124 DOMException: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame.
at b.$scope.printdoc (http://localhost:3000/js/docapp.js:46:32)
at fn (eval at compile (http://localhost:3000/js/core.js:242:306), <anonymous>:4:162)
at e (http://localhost:3000/js/core.js:287:342)
at b.$eval (http://localhost:3000/js/core.js:150:347)
at b.$apply (http://localhost:3000/js/core.js:151:52)
at HTMLAnchorElement.<anonymous> (http://localhost:3000/js/core.js:287:394)
at HTMLAnchorElement.dispatch (http://localhost:3000/js/jquery-3.2.1.min.js:3:10316)
at HTMLAnchorElement.q.handle (http://localhost:3000/js/jquery-3.2.1.min.js:3:8343)
我收到此错误。
【问题讨论】:
-
感谢您的回复@KishorVelayutham 链接源已仅在 iframe 中,并且也出现跨源错误
标签: angularjs iframe printing cross-domain same-origin-policy