我想在一些动作后重定向到外部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。
请帮助任何人。
试试这个
var newWin = win.open('some_url');
你能这样试试吗
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();