Improvement on window. showmodelessdialog

Source: Internet
Author: User
Window. showmodelessdialog method than window. the window popped up by the open method is different from the window popped up by the mode, so that the child window must be closed before the parent window can be operated. unfortunately, only IE is supported. The following method can bring up the Firefox "support" Mode window.

This method is inspired by the above cuteeditor. the pop-up window is modal, And the FF is to write a click method on the window. You only need to click the parent window to call the focus () of the Child Window () method, it seems to be "Modal"

VaR Useragent = Navigator. useragent. tolowercase ();
VaR Isfirefox = / Mozilla / . Test (useragent) &&   ! / (Compatible | WebKit) / . Test (useragent );
If (Isfirefox)
{
Window. showmodelessdialog = Function (URL)
{
VaR Windowname = (Arguments [ 1 ] = Null ? "" : Arguments [ 1 ]. Tostring ());
VaR Feature = (Arguments [ 2 ] = Null ? "" : Arguments [ 2 ]. Tostring ());
VaR Openedwindow = Window. Open (URL, windowname, feature );
Window. addeventlistener ( ' Click ' , Function () {Openedwindow. Focus ();}, False );
Return Openedwindow;
}
}
Else
{
// Parent window called in Child Window
// In ie, Use Role principal parent.doc ument
// Use Role extension opener.doc ument in FF
// The followingCodeThe method 'window. showmodelessdialog 'will be reloaded on IE and the parent window will be accessed using window. opener.
VaR Originfn = Window. showmodelessdialog;
Window. showmodelessdialog = Function (URL)
{
VaR Openedwindow = Originfn (URL, arguments [ 1 ], Arguments [ 2 ]);
Openedwindow. Opener = Window;
}
}
Function Popw ()
{
VaR Openedwindow = Window. showmodelessdialog ( ' Popwindow2.html ' , '' , ' Width = 400, Height = 400 ' );

}

it is actually very simple to say that it is broken, it's just a bit tricky to rewrite the showmodelessdialog method in IE below. originfn can "remember" The original showmodelessdialog method, which can be called in this way. I was surprised in my test.
through the above transformation, showmodelessdialog is much easier to use and compatible with the two browsers.
Source Code is not provided for downloading. All download files are posted.

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.