Try to search your question here, if you can't find : Ask Any Question Now ?

How to open a url in new window and then trigger ctrl + p (print)?

HomeCategory: stackoverflowHow to open a url in new window and then trigger ctrl + p (print)?
Avatarrupesh asked 3 months ago

I have iframe within a div and have a print button, on clicking print I want to open a new tab and trigger print action for the url being shown in iframe.
I am using Angular 7.

Solutions I tried so far:

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"   >
            </iframe>

<button (click)='print()'>Print</button>
</div>

component.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();

      }

Solution From iframe inside angular2 component, Property ‘contentWindow’ does not exist on type ‘HTMLElement’?

Error using above solution:

ERROR DOMException: Blocked a frame with origin
http://localhost:4200” from accessing a cross-origin frame.

I have a url and I just want to open it in new tab and print without clicking Ctrl+p

Thanks in advance for helping!

1 Answers
Best Answer
AvatarFernando answered 3 months ago
Your Answer

4 + 12 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com