Javascript “window.open” code won't work in Internet Explorer 7 or 8

烂漫一生 提交于 2019-11-27 14:27:28

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");
});

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.

The windowName argument can only contain alphanumeric characters and underscores (i.e. [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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!