问题描述
当我在$nextTick
中使用window.open(url, 'newwidnow', height, width, left, top ...)
想打开一个宽高为固定值,显示位置也为固定的新窗口时,代码执行到了window.open
,但是新窗口并没有出现,也没有报错。
如果不$nextTick
外部使用window.open
的话,就可以顺利打开新窗口。
而且不管是在$nextTick
里面还是在$nextTick
外部,console.log(this)
或者console.log(window.open(url, 'newwidnow', height, width, left, top ...))
都是一样的。
我的尝试
我尝试用setTimeout包住window.open也没有成功。程序能走到open,但是不管用。
setTimeout(() => {
window.open(url, 'newwidnow', height, width, left, top ...)
});
而且window.open('http://baidu.com','_self')
类似这样,我加了'_self'
,在$nextTick
中,就可以被执行,但是打开的窗口不是我想要的样式。
相关代码
// 在this.$nextTick中,window.open不能打开一个设定宽高,固定位置的新窗口
open (url) {
this.$nextTick(() => {
let openWindow = document.querySelector('.openWindow');
// 如果data-open属性是true则可以打开新页面,且不会刷新iframe或打开router-view
if (openWindow.dataset.open) { // 改为原生js获取自定义属性
let width = 550;
let height = 373;
let top = (window.screen.availHeight - height) / 2;
let left = (window.screen.availWidth - width) / 2;
window.open(url, 'newwindow', 'height=' + height + ',width = ' + width + ',top = ' + top + ',left = ' + left + 'toolbar = no,menubar=no,scrollbars=no,location=no,status=no');
}
if (!openWindow.dataset.open) { // open === false 再显示iframe
this.changeView(false); // 不显示router-view
// 子组件向父组件传
this.$emit('getIframeSrc', url);
}
});
}
我希望可以在$nextTick中window.open可以弹出一个制定好宽高和位置的新窗口,如下图:
应该是被浏览器 当成广告窗口拦截了