简体   繁体   English

打开新选项卡或窗口而不是弹出角度 2

[英]open new tab or window and not popup angular 2

I have research this for awhile now and I was not able to find a proper solution to this cause.我已经对此进行了一段时间的研究,但无法找到解决此问题的适当方法。

I have the code below...我有下面的代码...

<form name="userInfo" target="userInfo" onSubmit="window.open('', 'userInfo', 'width=650,height=463,location=no,toolbar=yes,menubar=yes,status=yes,resizable=yes,scrollbars=yes')" >
<input type="hidden" name="process" value="1"/>
<input type="hidden" name="key" value=""/>
<a href="javascript:submitUser();" class="BlueText"></a>
</form>

The above works fine in traditional html and popup blocker did not block the user submission.以上在传统 html 中工作正常,弹出窗口阻止程序没有阻止用户提交。

However, I am trying to do this on an angular 2 and it opens a popup instead of new tab.但是,我试图在角度 2 上执行此操作,它会打开一个弹出窗口而不是新选项卡。

user.html用户.html

..
<button type="button" (click)="userReport(user.id)">
..

user.component.ts用户.component.ts

userReport(id) {
doLogic(id);
this.windowOpen(id);
}

windowOpen(id) {
let actionUrl = this.getUrl(id); // this is a service
this.mapForm = document.createElement('form');
this.mapForm.target = userName;
this.mapForm.method = 'POST';
this.mapForm.action = actionUrl;
this.process = document.createElement('input');
this.process.setAttribute('type', 'hidden');
this.process.setAttribute('name', 'process');
this.process.setAttribute('value', '1');
this.mapForm.appendChild(this.process);
this.cookies = document.createElement('input');
this.cookies.setAttribute('type', 'hidden');
this.cookies.setAttribute('name', 'key');
this.cookies.setAttribute('value', this.key);
this.mapForm.appendChild(this.cookies);
document.body.appendChild(this.mapForm);
document.location.href = this.mapForm.submit();
window.open('', appName, 'width=630, height=535,status=yes,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes');
window.focus();
}

This above code in angular opens up a popup instead of new window (tab).上面的角度代码打开了一个弹出窗口而不是新窗口(选项卡)。 Why is this the case?为什么会这样? I dont see any difference between the original to the angular in terms of logic.就逻辑而言,我看不出原始版本与角度版本之间有任何区别。 Is there something I am missing?有什么我想念的吗?

You're oening in a new window with it:您正在使用它打开一个新窗口:

window.open('', appName, 'width=630, height=535,status=yes,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes');

You must to adapt it to your code:您必须使其适应您的代码:

window.open('http://www.yourlink.com', '_blank');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM