【发布时间】:2017-02-13 07:19:39
【问题描述】:
在创建商店记录并保留后,我正在努力寻找一种方法来在 then() 承诺中打开一个新窗口。
以下代码被chrome的弹窗拦截器拦截
var obj = this.get('store').createRecord('user', {
first_name: 'John',
last_name: 'Smith'
});
obj.save()
.then(function (user) {
window.open('http://google.com', '_blank'); // this is blocked by chrome pop-up blocker
})
.catch(function (error) {
this.set('errors', error.errorArray); // display errors in the template
});
此代码有效并绕过弹出窗口阻止程序,但我的问题是如果后端在保存期间抛出错误,我不想打开新窗口,因为最终用户没有成功创建,我想要他们仍然在他们可以看到错误的主窗口上。如果出现错误,我可以关闭窗口,但感觉不对,因为它看起来像是立即打开和关闭窗口的闪烁。
var window_handle = window.open('', '_blank');
var obj = this.get('store').createRecord('user', {
first_name: 'John',
last_name: 'Smith'
});
obj.save()
.then(function (user) {
window_handle.location.href = 'http://google.com'; // this is NOT blocked by chrome pop-up blocker
})
.catch(function (error) {
this.set('errors', error.errorArray); // display errors in the template
});
有人有更好的主意吗?
【问题讨论】:
标签: javascript ajax google-chrome ember.js popup-blocker