請參閱更新(11/27)以下showModalDialog;打開IE瀏覽器中的一個新窗口
我有一個啓動了它的iframe內容的模態窗口(ASP web表單應用程序)。我們需要將模式重定向到另一個頁面,但由於安全原因(Paypal處理頁面),它不能位於iframe內。在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);
}
};
更新11/27,以實例問題:
Interactive Example(需要IE10 +或任何好的瀏覽器)
以下就是這個問題的一個例子,所有的東西都是我們擁有的。當模式處於IE兼容模式時,它將打開一個新窗口而不是重定向模式。將頁面修改爲兼容模式不是一件容易的過程,因爲我們的應用程序依賴於兼容模式,並且外部模態頁面在各處廣泛使用。查看FireFox中的頁面(main.html)(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>
我可以得到我的回答一些建議嗎?這是爲你解決嗎? – Trevor
剛剛在驗證它的過程中! –