显示模态对话;在 IE 中打开一个新窗口
showModalDialog; Opens a New Window in IE
请参阅下面的更新(11/27(
我有一个模式窗口,它的内容在 iframe(ASP 网络表单应用程序(中启动。我们需要将模式重定向到另一个页面,但由于安全原因(PayPal处理页面(,它不能在 iframe 内。在 Chrome 和 IE 标准模式下,我们有代码可以将模态的 URL 正确更改为正确的 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,包含问题示例:
交互式示例(需要IE10+或任何好的浏览器(
以下是该问题的示例,所有设置都按照我们的方式设置。当模式处于 IE 兼容模式时,它会打开一个新窗口,而不是重定向模式。将页面固定为兼容模式并非易事,因为我们的应用程序依赖于兼容模式,并且外部模式页面在任何地方都广泛使用。在FireFox中查看页面(main.html((Chrome存在域安全问题(,它按预期工作;模式将完全重定向到新页面。
主.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>
莫代尔.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>
框架.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>
另一页.html
<html>
<head>
</head>
<body>
<strong>anotherpage.html</strong><br />
Success
</body>
</html>
出现您的问题是因为您正在使用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
相关文章:
- GWT获取新旧窗口大小
- 如何在新标签/窗口中编写文本文档
- 如何在鼠标悬停在另一个图像/链接上时显示新图像/窗口
- 从服务器 c# 打开 Outlook 新邮件窗口
- 获取用户输入以设置新的窗口参数
- 为什么我不能创建新的窗口实例
- 在c中按下一个按钮,打开两个新的窗口/选项卡(不同的外部站点)
- 在新浏览器/窗口上单击提交按钮后打开PHP操作
- 如何恢复窗口,而不是打开一个新的窗口,如果它有相同的url(仍然从上一个打开)
- 如何在不制作另一个新选项卡或新浏览器窗口的情况下在同一网页中播放MPG视频/音频文件
- 如何打开一个新的窗口/选项卡没有用户的干预,而不让它被阻止
- 打开所有链接不是我的网站的一部分,在新的窗口与jquery
- 打开一个新的窗口,而浏览器没有给出警告,这是一个弹出
- 在新的窗口jquery功能不工作
- 如何使图标出现在一个新的窗口
- 如何重定向到一个新的窗口后,点击选择关于html的选项
- 如何强制电子邮件链接打开在新的窗口
- 显示更多的信息悬停在一个新的窗口,如在facebook
- 如何使用谷歌签名与重定向,而不是一个新的窗口
- 在新的窗口打开页面,没有弹出阻止使用JavaScript目标_blank