[英]Detecting modal dialogs in javascript
Is there a way to detect when a page has been loaded in a modal dialog? 有没有一种方法可以检测何时在模式对话框中加载了页面? Such as when you call window.showModalDialog(). 例如当您调用window.showModalDialog()时。
A little background: I'm trying to get around the Forms Authentication problem of the login page appearing in the modal dialog, and subsequently the rest of the site when the user logs in. 一些背景知识:我试图解决模式对话框中出现的登录页面的表单身份验证问题,以及当用户登录时出现在网站的其余部分的问题。
Any ideas? 有任何想法吗?
For window.open you could check to see if the page you are currently on has a parent. 对于window.open,您可以检查当前所在的页面是否有父页面。
function parentExists(){
return (window.opener != null)? true : false;
}
Call this when your login page loads. 登录页面加载时调用此函数。 If it returns true, you are in a popup window (or modal). 如果返回true,则您处于弹出窗口(或模式窗口)中。 You can then close the page and redirect the parent. 然后,您可以关闭页面并重定向父级。
It's a little more tricky for a modal box because you don't have access to the opener. 对于模式框而言,这有点棘手,因为您无权访问打开器。 First, make sure all modal boxes are opened similar to this: 首先,确保打开所有模态框,如下所示:
window.showModalDialog('test.htm', self, <optional options>);
This will make sure something is passed into the window's arguements. 这样可以确保将某些东西传递到窗口的争论中。
Now add the following code on your login page: 现在,在您的登录页面上添加以下代码:
function parentExists()
{
var opener = window.dialogArguments;
return (opener == null)?false:true;
}
Edit: added information on modal boxes 编辑:在模式框上添加了信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.