对不起,如果这是一个重复的问题!
我有以下 Javascript 可以在 Firefox 中正常工作并生成一个弹出窗口。然而在 IE 9 中它什么都不做,而在 Chrome 中它就像一个链接并改变当前页面!
任何建议表示赞赏!
window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');
提前致谢。
对不起,如果这是一个重复的问题!
我有以下 Javascript 可以在 Firefox 中正常工作并生成一个弹出窗口。然而在 IE 9 中它什么都不做,而在 Chrome 中它就像一个链接并改变当前页面!
任何建议表示赞赏!
window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');
提前致谢。
这是一个工作示例
JS
function openWindow()
{
var width=668;
var height=548;
var page="http://google.com";
window.open(page, "awindow", "width="+width+",height="+height+",location=yes,scrollbars=yes, resizable=yes");
}
HTML
<a href="javascript:openWindow()">Open</a>
您是否正确创建了变量?
这段代码对我有用:
var page = 'page.php';
var name = 'pagename';
var width = 200;
var height = 100;
window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');
编辑
在我的 webapp 中,我使用以下功能打开窗口。它应该适用于所有浏览器。
function wopen(url, name, w, h, scrollb) {
scrollb = typeof(scrollb) != 'undefined' ? scrollb : 'no';
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
var win = window.open(url, name,
'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' +
'location=no, menubar=no, ' +
'status=no, toolbar=no, scrollbars=' + scrollb + ', resizable=yes');
// Just in case width and height are ignored
win.resizeTo(w, h);
// Just in case left and top are ignored
win.moveTo(wleft, wtop);
win.focus();
}
你在哪里打电话window.open?如果在页面加载期间作为其弹出窗口阻止程序的一部分进行调用,IE9 将阻止调用。Chrome 做了类似的事情,但将新窗口重定向到主选项卡(因此,让用户处于控制之中)。至于 Firefox... 检查您的 FF 弹出窗口阻止程序设置。