在angular2中重定向到外部URL

问题描述 投票:1回答:2

我想在一些动作后重定向到外部URL。请参考我的代码

            this.http.get(this.apiurl+'api/insert.php?did='+this.did).subscribe(data=>{
                  var jsonData = data.json();    
                  let url = jsonData.urlpass;
// redirect to this url like https://flipkart.com with my affilate params
window.open(url ,'_blank'); 
    });

这个window.open(url ,'_blank');显示了弹出窗口拦截器。

所以我试过这样的

<a #myDiv id="anchorID" href="url here" target="_blank"></a>
$("#anchorID")[0].click();

但是在subscribe方法中没有触发此click事件。

如果我使用var newWin = window.open(); newWin.location = url_pass;

它创建错误为Cannot assign to 'location' because it is a constant or a read-only property.

我想在没有弹出窗口阻止程序问题的新窗口中打开此外部URL。

请帮助任何人。

angular typescript
2个回答
0
投票

试试这个

var newWin = win.open('some_url');

0
投票

你能这样试试吗

component.html,以隐藏模式添加指向html的链接

  <a #popupLink class="btn-excel" (click)='popup()' 
                                       style="display:none">
    <span>Dummy link</span>
  </a>

component.ts

  @ViewChild('popupLink') popupLink;

   popup() {
    window.open("https://www.google.com", "_blank");
  }

  //some where from code
  popupLink.click();
© www.soinside.com 2019 - 2024. All rights reserved.