Javascript“window.open"代码在 Internet Explorer 7 或 8 中不起作用 [英] Javascript "window.open" code won't work in Internet Explorer 7 or 8
问题描述
我在我的网站上使用这段 jQuery/Javascript 代码来打开一个弹出窗口:
I am using this chunk of jQuery/Javascript code on my site to open a popup window:
$('#change_photo_link').click(function(){
$id = $('#id').attr('value');
window.open("photo.upload.php?id=" + $id,"Upload Photo",
"menubar=no,width=430,height=100,toolbar=no");
});
此代码适用于 Firefox 和 Chrome.它不适用于 IE7 或 IE8(尚未测试 IE6).IE 在 window.open
行上弹出错误.为什么?IE 给出的错误是无效参数",仅此而已.
This code works on Firefox and Chrome. It does not work on IE7 or IE8 (haven't tested IE6).
IE pops up an error on the line window.open
. Why? The error that IE gives is "Invalid Argument" and that's all.
推荐答案
导致它的第二个参数中的空格.如果您使用UploadPhoto"而不是Upload Photo",它会起作用:
It's the space in the second parameter that's causing it. If you use "UploadPhoto" instead of "Upload Photo", it works:
$('#change_photo_link').click(function(){
$id = $('#id').attr('value');
window.open("photo.upload.php?id=" + $id,"UploadPhoto",
"menubar=no,width=430,height=100,toolbar=no");
});
我似乎找不到任何官方原因来说明为什么 window.open()
的 windowName
参数中的空格会导致错误,但这很可能只是一个实现细节.windowName
用作内部引用,并且可以用作锚点或表单的目标属性的值,所以我猜 IE 无法在内部处理它.Gecko/Firefox 的参考文档说这个参数应该不包含空格,但显然 Gecko 的当前版本没有问题,如果有的话.
I can't seem to find any official reasons as to why having a space in the windowName
parameter of window.open()
causes an error, but it's likely just an implementation detail. The windowName
is used as an internal reference, and can be used as a value for a target attribute of an anchor or form, so I guess IE can't handle that internally. The reference docs for Gecko/Firefox says that this parameter should not contain spaces, but clearly current versions of Gecko don't have a problem with it if it does.
这篇关于Javascript“window.open"代码在 Internet Explorer 7 或 8 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!