показать модальный диалог; Открывает новое окно в IE

Пожалуйста, см. обновление (11/27) ниже

У меня есть модальное окно, которое запускается с содержимым в iframe (приложение веб-форм ASP). Нам нужно иметь модальное перенаправление на другую страницу, но оно не может быть внутри iframe из соображений безопасности (страница обработки Paypal). В стандартном режиме Chrome и IE у нас есть код, который правильно изменяет URL-адрес модального окна на правильный. Однако в режиме совместимости перенаправление приводит к открытию нового модального окна с правильным URL-адресом. Как мы можем остановить его от открытия нового окна и фактического перенаправления?

Это наш текущий код:

dialog.redirect = function (location, ignoreFrames) {
        /// <summary>Redirects the dialog to a new URL</summary>
        /// <param name="location" type="String"></param>
        /// <param name="ignoreFrames" type="Boolean">If true, the dialog's URL will be changed instead of any parent frame URLs</param>

        if (ignoreFrames === undefined) {
            ignoreFrames = true;
        }

        if (ignoreFrames === true) {
            if (window.top) {
                //Chrome and IE9+
                window.top.document.location.replace(location);
            } else {
                //This was a supposed fix but it did not change the outcome
                //<IE8 and compat mode
                var redirectLink = document.createElement("a");
                redirectLink.href = location;
                document.body.appendChild(redirectLink);
                redirectLink.click();
            }
        } else {
            window.document.location.replace(location);
        }
    };

Обновление от 27 ноября с примером проблемы:

Интерактивный пример (требуется IE10+ или любой другой хороший браузер)

Ниже приведен пример проблемы, где все настроено так, как у нас есть. Когда модальное окно находится в режиме совместимости с IE, оно открывает новое окно вместо перенаправления модального окна. Перевести страницу в режим совместимости — непростой процесс, так как наше приложение использует режим совместимости, а внешняя модальная страница широко используется везде. Просмотр страницы (main.html) в FireFox (в Chrome есть проблема с безопасностью домена) работает, как и ожидалось; модальное окно полностью перенаправляется на новую страницу.

main.html

<html>
<head></head>
<body>
    <a href="javascript:window.showModalDialog('modal.html', self, 'status:no;resizable:yes;help:no;scroll:no;width:1000;height:600')">Open Modal</a>
</body>
</html>

modal.html

<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]--> 
<!--[if IE 7]>    <html class="lt-ie9 lt-ie8"> <![endif]--> 
<!--[if IE 8]>    <html class="lt-ie9"> <![endif]--> 
<!--[if gt IE 8]><!--> <html class=""> <!--<![endif]-->
    <head>
        <title id="tagTitle"></title>
    </head>
    <body style="margin:0px">     
        <form name="Form1" method="post" action="" id="Form1">
            <strong>modal.html</strong><br />
            <iframe frameborder="1" src="frame.html" scrolling="yes"></iframe>
        </form>
    </body>
</html>

frame.html

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6" xmlns="http://www.w3.org/1999/xhtml"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7" xmlns="http://www.w3.org/1999/xhtml"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8" xmlns="http://www.w3.org/1999/xhtml"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9" xmlns="http://www.w3.org/1999/xhtml"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html class="" xmlns="http://www.w3.org/1999/xhtml">
<!--<![endif]-->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<strong>frame.html</strong><br />
<a href="javascript:void(0)" onclick="redirectToCart();" title="My Cart">Trigger Redirect</a>

<script type="text/javascript">
    var redirect = function (location, ignoreFrames) {
        /// <summary>Redirects the dialog to a new URL</summary>
        /// <param name="location" type="String"></param>
        /// <param name="ignoreFrames" type="Boolean">If true, the dialog's URL will be changed instead of any parent frame URLs</param>

        if (ignoreFrames === undefined) {
            ignoreFrames = true;
        }

        if (ignoreFrames === true) {
            window.top.document.location.replace(location); //IE will create a new window at this point, instead of changing the modal's URL
        } else {
            window.document.location.replace(location);
        }
    };

    function redirectToCart() {
        redirect('anotherpage.html', true); //Change this to false to see just the inner frame's URL change
    }
</script>
</body>
</html>

anotherpage.html

<html>
<head>

</head>
<body>
    <strong>anotherpage.html</strong><br />
    Success
</body>
</html>

person Jason Kaczmarsky    schedule 25.11.2013    source источник
comment
Могу ли я получить отзыв о своем ответе? Это решило это для вас?   -  person Trevor    schedule 02.12.2013
comment
Как раз в процессе проверки!   -  person Jason Kaczmarsky    schedule 02.12.2013


Ответы (1)


Ваша проблема возникает из-за того, что вы используете showModalDialog, что приводит к такому поведению при использовании IE.

Вы можете прочитать об этом здесь:

showModalDialog открывает новое окно

Если вы хотите продолжить использовать showModalDialog, вот обходной путь:

modal.html

<head>
    <base target="_self" />
    ...
</head>
<body style="margin:0px">     
        ....
        <a href="anotherpage.html" id="go" style="display:none;"></a>
    </form>
</body>

frame.html

function redirectToCart() {
    window.parent.document.getElementById('go').click(); 
}

Пример

http://plnkr.co/edit/ClxlWqkzBmTy93kJzuru?p=preview

person Trevor    schedule 27.11.2013
comment
Ах, у меня было предчувствие, что это было что-то вроде этого, но я не мог найти никаких доказательств. Спасибо, это исправлено. - person Jason Kaczmarsky; 02.12.2013