我有一个div中的iframe和一个print按钮,单击print我想打开一个新的选项卡并为iframe中显示的url触发print操作。
我用的是角7。
到目前为止我尝试过的解决方案:
How to open a link new tab with print command?
HTML
<div>
<iframe #iframe [src]="url" width="100%" id='event-print-iframe'
name="targetframe" allowTransparency="true" frameborder="0" >
</iframe>
<button (click)='print()'>Print</button>
</div>
组件.ts
import {
//...
ElementRef,
ViewChild
} from '@angular/core';
@ViewChild('iframe') iframe: ElementRef;
print()
{
let content = this.url;
let doc = this.iframe.nativeElement.contentDocument || this.iframe.nativeElement.contentWindow;
doc.open();
doc.write(content);
doc.close();
}
解决方案来自
iframe inside angular2 component, Property 'contentWindow' does not exist on type 'HTMLElement'?
使用上述解决方案时出错:
错误域异常:阻止了具有原点的帧
“。”
http://localhost:4200
“从访问交叉原点帧。
我有一个网址,我只想在新的标签页中打开它,不需要点击ctrl+p就可以打印出来
提前谢谢你的帮助!