Bitte siehe Update (11/27) untershowModalDialog; Öffnet ein neues Fenster in IE
Ich habe ein modales Fenster, das gestartet wird, mit seinem Inhalt in einem iframe (ASP Webforms Anwendung). Wir müssen die modale Weiterleitung zu einer anderen Seite haben, aber es kann nicht aus Sicherheitsgründen im Iframe sein (Paypal-Verarbeitungsseite). Im Chrome- und IE-Standardmodus haben wir einen Code, der die URL des Modals korrekt in die richtige ändert. Im Kompatibilitätsmodus bewirkt die Umleitung jedoch, dass ein neues modales Fenster mit der richtigen URL geöffnet wird. Wie können wir verhindern, dass ein neues Fenster geöffnet und tatsächlich umgeleitet wird?
Dies ist in unserem aktuellen Code:
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);
}
};
-Update 11/27, mit Beispiel der Ausgabe:
Interactive Example (Benötigt IE10 + oder ein guter Browser)
Die folgenden ist ein Beispiel für das Problem, mit allem eingerichtet, wie wir es haben. Wenn sich das Modal im IE-Kompatibilitätsmodus befindet, wird ein neues Fenster geöffnet, anstatt das Modal umzuleiten. Das Korrigieren der Seite im Kompatibilitätsmodus ist kein einfacher Prozess, da unsere Anwendung auf den Kompatibilitätsmodus angewiesen ist und die äußere modale Seite weitgehend überall verwendet wird. Wenn die Seite (main.html) in FireFox angezeigt wird (Chrome hat dieses Domänensicherheitsproblem), funktioniert es wie erwartet; Das Modal wird vollständig auf die neue Seite umgeleitet.
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>
Kann ich ein Feedback auf meine Antwort? Hat das für Sie gelöst? – Trevor
War gerade dabei, es zu überprüfen! –