Today we talk about window.open again because I found a little bit more fun, the details of which we will explain later. Talk to window.open, have to explain his use method, there are two main forms:
- window.open () does not have any parameters, this way you can open a page with a new tab
- window.open (URL, name, pars), with parameters to open the window in the current page
The detailed use method, before has had the introduction, if wants to understand, may click here. Now that you know how to use it, here are a few special properties and methods (all of which are the same domain pages):
- window.open () open window or New tab returns window object
- In a new window you can also take a Window object to the parent window (which performs the window.open environment) by Window.opner
- Window.close () method to close the window
- Window.onunload and Window.onbeforeunload events, monitoring window shutdown condition
After learning how to use the above method, we introduce a clever way to use it. A total of two pages: the first page (window.open.html) is the function of a new window, the second page (window.close.html) for the new open window of the request return information, you can in the first page, listen to the new open window request data. Here are two pages: the window.open.html page reads as follows:
<! Doctype>Window.close.html page content is as follows:<! Doctype>
Through the above described in this way can be resolved, micro-blog and other third-party login without refreshing the parent page to know the return status of the demand. It is also a good way to resolve cross-domain requests (security does not know how). Test small example share such a small trick today ~window.open Tips for sharing