I am using this chunk of jQuery/Javascript code on my site to open a popup window:
我在我的网站上使用这一块jQuery / Javascript代码打开一个弹出窗口:
$('#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");
});
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.
此代码适用于Firefox和Chrome。它不适用于IE7或IE8(尚未测试IE6)。 IE在行window.open上弹出一个错误。为什么? IE给出的错误是“无效参数”,这就是全部。
2 个解决方案
#1
32
It's the space in the second parameter that's causing it. If you use "UploadPhoto" instead of "Upload Photo", it works:
它是导致它的第二个参数中的空间。如果您使用“UploadPhoto”而不是“上传照片”,它的工作原理如下:
$('#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");
});
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.
我似乎无法找到任何官方原因,为什么在window.open()的windowName参数中有一个空格会导致错误,但它可能只是一个实现细节。 windowName用作内部引用,可以用作锚或表单的目标属性的值,所以我猜IE在内部无法处理。 Gecko / Firefox的参考文档说这个参数不应该包含空格,但显然当前版本的Gecko没有问题。
#2
9
The windowName
argument can only contain alphanumeric characters and underscores (i.e. [A-Z0-9_]
).
windowName参数只能包含字母数字字符和下划线(即[A-Z0-9_])。
You must change
你必须改变
window.open("photo.upload.php?id=" + $id,"Upload Photo",
"menubar=no,width=430,height=100,toolbar=no");
to
至
window.open("photo.upload.php?id=" + $id,"Upload_Photo",
"menubar=no,width=430,height=100,toolbar=no");
or some other name that doesn't have spaces.
或其他一些没有空格的名称。
See https://developer.mozilla.org/En/DOM/Window.open.
请参阅https://developer.mozilla.org/En/DOM/Window.open。
#1
32
It's the space in the second parameter that's causing it. If you use "UploadPhoto" instead of "Upload Photo", it works:
它是导致它的第二个参数中的空间。如果您使用“UploadPhoto”而不是“上传照片”,它的工作原理如下:
$('#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");
});
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.
我似乎无法找到任何官方原因,为什么在window.open()的windowName参数中有一个空格会导致错误,但它可能只是一个实现细节。 windowName用作内部引用,可以用作锚或表单的目标属性的值,所以我猜IE在内部无法处理。 Gecko / Firefox的参考文档说这个参数不应该包含空格,但显然当前版本的Gecko没有问题。
#2
9
The windowName
argument can only contain alphanumeric characters and underscores (i.e. [A-Z0-9_]
).
windowName参数只能包含字母数字字符和下划线(即[A-Z0-9_])。
You must change
你必须改变
window.open("photo.upload.php?id=" + $id,"Upload Photo",
"menubar=no,width=430,height=100,toolbar=no");
to
至
window.open("photo.upload.php?id=" + $id,"Upload_Photo",
"menubar=no,width=430,height=100,toolbar=no");
or some other name that doesn't have spaces.
或其他一些没有空格的名称。
See https://developer.mozilla.org/En/DOM/Window.open.
请参阅https://developer.mozilla.org/En/DOM/Window.open。