Use the unknown type to determine the current window type

Source: Internet
Author: User
ASP. NET provides many page authentication modes for me. Because Integration authentication has high requirements on client deployment, we may not be able to deploy well in many cases. In the passport Authentication mode, I do not know whether enterprise applications are used. What does it feel if you want to pin your security to a third party? Therefore, form authentication is a relatively useful authentication solution.

When form authentication is used, the defined login page is automatically displayed after the authentication times out. After logon, we can return to the original timeout page. In general, this is a good user experience, but this automatic processing mechanism for form authentication sometimes brings us trouble. That is, when we use modal dialog in the system, the problem arises.

If my page A is a normal page, you can open the modal dialog B page by clicking a button or link on it. At this time, if the form authentication login has timed out, We click a page to start B. The depressing problem is that the form authentication automatically directs the login page to modal dialog B. Whatever it is, log in to modal dialog. The new problem comes again. When the redirection is back to page A, ie opens a new window, which is a mess. Add <base target = _ seft> On the login page. Now, the new ie window does not appear. The a page that is redirected back will stay in the modal dialog, and the system will be dizzy again.

if we can determine the window type on the login page, we can give the user a friendly prompt to tell the user that this login has timed out, you must log on to the login page and log on again. Can we determine the type of the page window? This is indeed a very unreasonable requirement, Because regardless of the window object method: open, showmodaldialog and showmodelessdialog open new windows are a complete window object instance. All properties of the window object are unique. After careful research, these methods will still affect the properties of the window object. Among them, open is better to judge, because the window opened by open is used, and the window of the new window. opener points to its parent window. The window. Opener of the new window opened by showmodaldialg and showmodelessdialog is always undefined. However, for normal follow links, the window. Opener of the new page is also undefined. If you click the link to open the IE window (whether SHIFT + Click or target = _ blank), the window. Opener of the new window is the same as window. Open, pointing to its parent window.

It seems that there is no way to answer questions, but I think of the window attribute dialogarguments that we often use after showmodaldialog and showmodalessdialog. What is the value of dialogarguments? Of course, if we assign a value to the second parameter when using showxxx, the window. dialogarguments in the new window is the value assigned. It seems that this parameter can be used to determine whether the window we started is modal dialog. However, this method is too dependent on the specific implementation, that is, the parameter must be passed to modal dialog no matter what the situation is, the risks are quite high. If we do not assign a value to the second parameter of showxxx, what will happen? First, we thought it would be undefined or null. However, when we execute typeof (window. dialogarguments) in modal dialog, we accidentally find that the result is of the unknown type! So I immediately looked at the new window opened by the open method. The result of executing typeof (window. dialogarguments) is: undefined.

Finally, we finally had a different village. With the unknown type in the modal dialog and the undefined type in the general ie window, we can not forcibly pass or rely on any parameter identifiers, the actual type of the window where the current page is located is normal ie window or modal window (modal or modaless ~~

Detection Code (Modal and modaless cannot be distinguished ): < Script Language = "JavaScript" >
VaR Type =   Typeof (Window. dialogarguments );
VaR Openertype =   Typeof (Window. opener );
If (Type ! = 'Undefined' && Openertype = 'Undefined ')
{
Alert ('the page is loadedInA modal or modaless window .');
}
Else
{
Alert ('the page is loadedInA normal ie window .');
}
</ Script >

This check is passed in IE 6.0 SP2, but I don't know when the unknown type is introduced to the script object. If you are interested in using IE 6.0 or earlier, you may want to test this method and inform the test result and the IE version number.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.