Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Redirect to an external URL and open in a new tab

I'm trying to Open a new page when user clicks on a link. I can't use Angular 2 Router, because it doesn't have any functionalities to redirect to an external URL.

so, i'm using window.location.href="...";

html code:

<button (click)="onNavigate()">Google</tn-submenu-link> 

typescript code:

onNavigate(){         //this.router.navigateByUrl("https://www.google.com");         window.location.href="https://www.google.com";     } 

But how can I open it in a new tab? when using window.location.href ?

like image 686
Varun Avatar asked Mar 13 '17 23:03

Varun


People also ask

How to navigate to external URL in Angular in new tab?

To open the link in a new tab, we can use the <a> element by passing a target attribute with a value _blank . Note: In the example above, we have used the href attribute to pass a link instead of routerLink because the routerLink attribute appends the URL to the current URL path.

How to open route in new tab in Angular?

Left click -> go to corresponding route / page without a new reload ; Right click -> Open in new tab / window options and would naturally load a new page when using this navigation.

How do I redirect an external URL from angular2 route without using component?

To redirect to an external URL from Angular route without using component, we can set window. location. href to a value in our code.

How do I redirect a new tab and make it open?

In the main page section of the editor under the Buttons tab, select a button and turn it on. Then select “redirect to website” from the click action dropdown menu.


1 Answers

onNavigate(){     window.open("https://www.google.com", "_blank"); } 
like image 131
Martin Ocando Avatar answered Sep 20 '22 22:09

Martin Ocando