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

前端 未结 9 637
离开以前
离开以前 2020-12-03 00:36

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.

<
9条回答
  •  遥遥无期
    2020-12-03 01:09

    Another possible solution is:

    const link = document.createElement('a');
    link.target = '_blank';
    link.href = 'https://www.google.es';
    link.setAttribute('visibility', 'hidden');
    link.click();
    

提交回复
热议问题