问题描述
我在我的网站上使用这一块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代替上传照片,它可以工作:
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");
});
我似乎无法找到任何正式理由为什么在<$ c中有空格$ c> windowName 的参数window.open()
会导致错误,但它可能只是一个实现细节。 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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!