Let's talk about it again today window.open It's because I found a fun trick , The details will be explained later .

 
    Talk about window.open, I have to explain how to use it , There are two main forms :
 
  • window.open() There are no parameters , This way you can open pages with new tags
  • window.open(url, name, pars), With parameters, you can open a window on the current page
 
    Detailed usage , There was an introduction before , If you want to know , Sure Click here .
 
    Know how to use , Next, I'll introduce some special properties and methods ( The following are all the same domain pages ):
 
  1. window.open() An open window or a new label returns to the window's window object
  2. You can also get the parent window in the new window ( perform window.open Environment ) Of window object , adopt window.opner
  3. window.close() Method to close the window
  4. window.onunload and window.onbeforeunload event , Monitor window closing
 
    After understanding the above usage , Introduce a very clever way to use .
 
    There are two pages : The first page (window.open.html) Its function is to open a new window , Second page (window.close.html) Return information for a new window request , It can be found on the first page , Listen to the data requested by the new window . Here are two pages :
 
    window.open.html The content of the page is as follows :
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<! DOCTYPE >
< html >
< head >
    < meta charset="utf-8">
    < title >window.open Tips </ title >
</ head >
< body >
I'm the window :window.open
< button id="openWindow"> Click new window </ button >
< script type="text/javascript">
(function() {
    var openWindowEl = document.getElementById('openWindow');
    var newWindow;
    var data;
   
    window.windowName = 'window.open';
 
    openWindowEl.onclick = function() {
        newWindow = window.open('window.close.php', '_blank', 'width=500,height=500;');
        // need window.close.html js Only after normal execution
        /*setTimeout(function() {
            console.log(newWindow.userName);
        }, 1000);*/
        newWindow.onbeforeunload = function() {
            userName = newWindow.windowName;
            data = newWindow.data;
        }
       
        newWindow.onunload = function() {
            alert(userName);
            if(data.errno == 0) {
                alert(data.errmsg);
            }else {
                alert(data.errmsg);
            }
        }
    };
})();
</ script >
</ body >
</ html >
  
window.close.html The content of the page is as follows :

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<! DOCTYPE >
< html >
< head >
    < meta charset="utf-8">
    < title >window New window </ title >
</ head >
< body >
I'm the window :window.close
< script type="text/javascript">
(function() {
    window.windowName = 'window.close';
    if(Math.random() > 0.5) {
        window.data = {
            errno: 0,
            errmsg: ' success ~'
        };
    }else {
        window.data = {
            errno: 1,
            errmsg: ' Data exception ~'
        }; 
    }
    setTimeout(function() {
        // I got it from my father's window window
        alert(window.opener.windowName);
    }, 100);
    setTimeout(function() {
        window.close();
    }, 1000);
})();
</ script >
</ body >
</ html >
 
    In this way, we can solve , Third party login such as microblog does not need to refresh the parent page to know the return status . At the same time, it is a better way to solve cross domain requests ( Security doesn't know how to ). Test small examples
 
    Let's share this tip today ~
http://www.cnblogs.com/xiaoheimiaoer/p/4734977.html

window.open Share your tips ( turn ) More articles about

  1. window.open Share your tips

        Let's talk about it again today window.open It's because I found a fun trick , The details will be explained later .       Talk about window.open, I have to explain how to use it , There are two main forms :   win ...

  2. Python Coding tips to share 【 A novice must learn 】

        This time I share python Programming tips are summarized as follows , Hopefully that helped , It's very practical : Many people learn from Python In the process, you will encounter all kinds of troubles , There's no one to answer questions for . For this reason, Xiaobian built a Python Free Q & A in the whole stack . skirt : Yijiuwuqi ...

  3. javascript About China &amp;&amp; and || Expression tips sharing

    If you're new , And after reading all the details of these skills and each skill is if you use them later in your work , You will write more concise and efficient JavaScript Program . exactly , JavaScript Experts have used these techniques to write a lot of powerful , high ...

  4. Visual Studio Template code comments tips to share

    In the daily development process , It's hard to avoid such a demand : Each class file or interface file you create needs to be marked with the name of the author and the purpose of the class . It's annoying if we need to write this information every time we create a file . not so bad Visual Studio Give me a ...

  5. Android Studio Use tips : Extract method code fragment

    http://www.jb51.net/article/65510.htm Today I'd like to introduce a very useful Studio Tips, Sometimes we write too much code inside a method , And then I want to extract some code and ...

  6. android Browser development tips ( turn )

    My friends and I have been doing browsers for a while , Share some tips , Write a part first , Write slowly , It's also advertising our browser Our browser is going online , It's called sofa browsing 1. Right click menu in web page public boolean onLo ...

  7. openinstall Integration tips

    introduction : I've been working on one recently iOS End of the game , Want to realize the function of automatically associating friends when installing , Just post to ask if you have any good ideas . In the post, France thought of this good SDK, Through it, we also achieve , The function of automatically entering friends' game room after installation . Here I'll share ...

  8. Beef press release system -- Study Web Summary of tips

    2014 year 11 month 10 Japan , It's an unforgettable day . This day . Small make up the BS Learning begins .BS The beginning of , Start with the sirloin news system . What I learned before is CS Knowledge of , After the soft test . Start learning BS, Contact BS For a few days , Follow the beef belly teacher ...

  9. Beef press release system -- Study Web Summary of tips

    2014 year 11 month 10 Japan , It's an unforgettable day , This day , Small make up the BS Learning begins ,BS The beginning of , Start with the sirloin news release system , What I learned before is CS Knowledge of , After the soft test , Begin to learn BS, Contact BS For a few days , Follow the beef belly teacher ...

Random recommendation

  1. jQuery Summary of events and animations in

       1. load DOM     1.1.window event window.onload=function(){}.... opportunity : After other resources are loaded , Re execution    $(function(){}) ……: It's just ...

  2. s2 devMode cmdshell

    s2 devMode cmdshell   Only batch validation is supported , Command execution link :http://pan.baidu.com/s/1sl7tgRV password :wud8 It can also be done through outscan One click access to , After the import t ...

  3. Visual studio Use of generated events 、xcopy Realization dll Copy operation 、

    IF NOT "$(ConfigurationName)"=="publish" exit /B 0if not exist $(TargetPath)publ ...

  4. BZOJ 1831 &amp; It's just one. DP....

    The question : for instance ,4 2 1 3 3 It contains 5 In reverse order :(4, 2), (4, 1), (4, 3), (4, 3), (2, 1). It is a pity , Because of the age , Some of these numbers are blurry , For the sake of prescription ...

  5. Python Concise grammar

  6. Yaf Use the pits you encounter

    yaf Use experience : 1.    yaf Use in __get After the magic method , The template cannot render automatically , You need to specify the template manually ? 1 $this->getView()->display('index/in ...

  7. OVS vxlan Substructure analysis - Every day 5 Minutes to play OpenStack(148)

    The last section created vxlan100_net And deploy instance, Today we're going to analyze the underlying network structure . The control node perform ovs-vsctl show: br-int br-int Connected as follows port: ta ...

  8. .net core Deploy centos7 First try

    I've been making time for .net core, There are many pioneers who have contributed a lot of articles in this field , Today, let's go through the pit where our predecessors walked ...... Pay attention to the beginning centos7, I used to have a computer full of 6. Several versions of , And then I was confused ...

  9. ES--06

    The first 51. New to search engine _ On the computer, hands-on, multi search conditions combined query Syllabus GET /website/article/_search{ "query": { "bool": ...

  10. sql New statement

    SQL Statement to find duplicate data :  select partner_id,* from sale_origin where partner_id in (select   partner_id from  ...