最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Detecting modal dialogs in javascript - Stack Overflow

programmeradmin8浏览0评论

Is there a way to detect when a page has been loaded in a modal dialog? Such as when you call 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?

Is there a way to detect when a page has been loaded in a modal dialog? Such as when you call 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?

Share Improve this question edited May 1, 2013 at 16:23 Zachary Yates asked May 27, 2009 at 19:54 Zachary YatesZachary Yates 13.4k7 gold badges59 silver badges89 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

For window.open you could check to see if the page you are currently on has a parent.

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). 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

发布评论

评论列表(0)

  1. 暂无评论