简体   繁体   English

IE8 window.opener问题

[英]IE8 window.opener problems

Having problems with IE8... IE8出现问题...

I have a button that onclick fires the showImageBrowser() function. 我有一个按钮,onclick会触发showImageBrowser()函数。

function showImageBrowser(params) {
var open = window.open('http://localhost/admin/browse?'+params,'newwin','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=950,height=500');
    if (!open) {
        alert('Could not open the image browser, please disable your popup blocker.');
    }
}

Now in the image browser when you click on an image it calls this function: 现在,在图像浏览器中,当您单击图像时,它将调用此功能:

function selectFile(url, el) {
    window.opener.replaceImage('Test_Image', url);
    window.close();
}

Which is calling the replaceImage() function in the parent window, as expeted. replaceImage() ,它正在父窗口中调用replaceImage()函数。

This is the code: 这是代码:

function replaceImage(el, url) {
  $('#'+el).html('<a href="'+url+'" target="_blank" class="image">'+basename(url)+'</a>');
  $("input[name='"+el+"']").val(url);
}

Now if you click on the original showImageBrowser() button for the second time, IE will bring up the window but this time it freezes for a few seconds and then you get the alert "Could not open the image browser, please disable your popup blocker." 现在,如果您第二次单击原始的showImageBrowser()按钮,则IE将打开该窗口,但这次冻结了几秒钟,然后您收到警报“无法打开图像浏览器,请禁用弹出窗口阻止程序”。

This works fine in Firefox (obviously) but not in IE. 这在Firefox中(显然)可以正常工作,但在IE中则不能。 I haven't even tried it in IE7/6 because if it doesn't work in 8 then I know I'm going to have problems. 我什至没有在IE7 / 6中尝试过它,因为如果它在8中不起作用,那么我知道我会遇到问题。

Any advice? 有什么建议吗?

I don't know the background behind this but it looks like IE won't window.open into an existing window - maybe for security purposes, I don't know. 我不知道其背后的背景,但看起来IE不会window.open进入现有窗口-也许出于安全目的,我不知道。

You could try replacing newwin by something random (different) every time, which will open a new window every time you call showImageBrowser() . 您可以尝试每次用随机(不同)的东西替换newwin ,每次调用showImageBrowser()都会打开一个新窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM