打开新标签页或窗口,不弹出角度2

时间:2018-12-17 15:14:49

标签: javascript html angular

我已经对此进行了一段时间的研究,但未能找到适当的解决方案。

我有下面的代码...

<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>

以上操作在传统的html中很好,并且弹出窗口阻止程序没有阻止用户提交。

但是,我正在尝试在角度2上执行此操作,它会打开一个弹出窗口,而不是新的标签页。

user.html

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

user.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();
}

上面的angular代码以弹出窗口代替了新窗口(标签)。为什么会这样呢?在逻辑方面,我没有看到原始版本与角度版本之间有任何区别。有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

您正在使用它在新窗口中进行

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

您必须使它适应您的代码:

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

BR