The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.
If target="_blank" , the linked document will open in a new tab or (on older browsers) a new window.
1) select "open link in new background tab" from the context menu (second choice), 2) use middle-click on the link with your mouse; 3) use Ctrl+leftclick on the link with your mouse, 4) designate a mouse gesture to open a background tab when you perform it over a link.
Use window.open()
. It's pretty straightforward !
In your component.html
file-
<a (click)="goToLink('www.example.com')">page link</a>
In your component.ts
file-
goToLink(url: string){
window.open(url, "_blank");
}
just use the full url as href like this:
<a href="https://www.example.com/" target="_blank">page link</a>
Just add target="_blank"
to the
<a mat-raised-button target="_blank" [routerLink]="['/find-post/post', post.postID]"
class="theme-btn bg-grey white-text mx-2 mb-2">
Open in New Window
</a>
I have just discovered an alternative way of opening a new tab with the Router.
On your template,
<a (click)="openNewTab()" >page link</a>
And on your component.ts, you can use serializeUrl to convert the route into a string, which can be used with window.open()
openNewTab() {
const url = this.router.serializeUrl(
this.router.createUrlTree(['/example'])
);
window.open(url, '_blank');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With