Window. Open rebuild plan

Source: Internet
Author: User

Some people discussed window a few days ago. open (), so the pop-up page is really not very friendly, I was wondering if there could be such a piece of JavaScript that can change the window. open () pops up an IFRAME, which not only facilitates the use of window. the open () dialog box is displayed. opener accesses the parent page.

Basic knowledge
1. open () method: Add a method function a (MSG) {alert (MSG) ;}on the page, you can use window. A ("MSG") access. If the function name is alert or open, some built-in functions will be "overwritten ", this method can be extended to access the parent page on the pop-up page: window. opener. A ("MSG ");. the open method was born.
2. You may think that the window method can be "rewritten", so can the window attribute be re-assigned? This is hard to say.
3. arguments array: You can use this array to access all parameters that call and return functions within the range of a function. if a function has only one parameter and you have two parameters, this method will also be called (in fact, this is the Javascript polymorphism)
4. Simplest: An iframe is displayed. First, overwrite the entire body in the background layer on the page body, and then put the IFRAME on the layer.

Native method parameters
Window. Open (URL [, windowname] [, features]); // returns the popwindow object

MainCode

Window. Open = Function (URL) // Only URL parameters
{
// Parse featureas
VaR Features = Typeof (Arguments [ 2 ]) = " Undefined " ? "" : Arguments [ 2 ]. Tostring (); // Method for obtaining the third parameter

Format the featurs parameter into an object.

VaR Featurearray = Features. Split ( " , " );
VaR Featureobject = New Object ();
For ( VaR I = 0 ; I < Featurearray. length; I ++ )
{
VaR Array = Featurearray [I]. tostring (). Split ( " = " );
Featureobject [array [ 0 ] = Array [ 1 ];
}
// Featureobject. Height

Override the methods and properties of the pop-up window page VaR Interval = Null ;
Interval = Window. setinterval ( Function (){
If (Iframepop.doc ument ! = Null ) // Find iframepop.doc ument.
{
Window. clearinterval (interval );
Interval = Null ;

Iframepop. Close = Function () // Rewrite iframepop. Close but only work in FF one time !!
{
// In IFRAME, window. parent is used to access the parent page.
Iframepop. Parent. closepop ();
}
Iframepop. Opener = Window; // Does not work in Firefox
}
}, 300 );

This code is a bit strange and I have been pondering for a long time. The method of rewriting the sub-window must obtain the DOM structure of the sub-window, so I can only wait until the sub-window is loaded and I will try iframepop. close does not work when it is written outside the loop. In this way, when close () is called in the subwindow, it calls the closepop () method of the parent page.

The comments are also mentioned. Unfortunately, there is some trouble in Firefox. Setting the opener attribute of the subwindow to the current window does not work. It is a bit confusing here, firefox allows the open method to be rewritten. Why is it so stingy to set opener? Is this setting more dangerous than rewriting the open method? Therefore, only window. parent can be used to access the parent window in the Child Window.
What's more strange is that the close method can be rewritten only when Firefox is closed for the first time. When a subwindow is opened again, the subwindow may be cached ??

Download instance code

Following the above ideas, I also made a good arrangement of window. showmodelessdialog.
The two should be posted on the homepage. The following are your comments.

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.