JS 06 bom frame window page scheduled task

Keywords: Javascript

BOM(Broswer Object Model)
All properties and methods of window can omit "window."
Method:
Frame window
1. warning box
window.alert("msg");
2. confirmation box
window.confirm("msg");
3. question box
window.prompt("msg","defaulvalue")
page
1. Open a window
window.open()
2. Used in the child window to represent the window object of the parent window
window.opener
window.opener.fatherSayHello();  Method to call the parent window
window.opener.a

 

3. Close the current window
window.close()
window.close(); close current
window.opener.close(); close parent window

 

Timing task
1. Scheduled tasks
var taskid = window.setTimeout(function,ms);
window.setTimeout("alert('hello!')", 5000);

 

2. Perform tasks at intervals
var taskid = window.setInteval(function,ms);
3. Clear scheduled tasks
window.clearTimeout(taskid);
4. Clear the interval to execute the task
window.clearInteval(taskid);
 
Print screen
//long*wide
console.log(screen.width + "*" + screen.height)

 

Back off
window.history.back();

 

Forward
window.history.forward();

 

Refresh
window.location.reload();//Refresh
window.location.href = window.location.href;//Refresh

 

Go forward (x), backward (x), refresh (0),
window.history.go(x)

 

link
window.location.href = "http://www.baidu.com";

 

User agent browser kernel
console.log(window.navigator.userAgent)

 

Frame window
//Whatever window Properties and methods of can be omitted“ window."
    <script type="application/javascript">
//        Warning box
        function testAlert(){
            var result=window.alert("This is a warning box")
            console.log(result);
        }

//      confirm  Confirmation box
        function testConfirm(){
            var result =window.confirm("Are you sure you want to leave?");
            if(result){
                alert("look forward to seeing you next time!")
            }else{
                alert("Then you're browsing!")
            }
            consol.log(result);
        }
//      prompt Inquiry frame
        function testPrompt(){
            var result = window.prompt("Please input U Shield password","for example:123456");
            console.log(result);
        }



    </script>

<body>
<button onclick="testAlert();">testAlert</button>
<button onclick="testConfirm();">testConfirm</button>
<button onclick="testPrompt();">testPrompt</button>
</body>

 

page
//Sub page
  <script type="application/javascript">
        function sayHello(){
            alert("hello world")
        }
            //Open a window
        function callFatherMethod(){
            window.opener.fatherSayHello();
            window.opener.a
        }
            //Close this window
        function testClose(){
            window.close();
        }
            //Close parent window
        function testFatherClose(){
            window.opener.close();
        }

    </script>

<body>
<button onclick="callFatherMethod()">Method to call the parent window</button>
<button onclick="testClose()">Close this window</button>
<button onclick="testFatherClose()">Close parent window</button>
</body>

//Parent page
<script type="application/javascript">
          var a  = 10;
       window.onload = function(){
            console.log(window);
            console.log("11111111111")
        }
            //Open a new window
        function testOpen(){
            var sonwindow = window.open("son.html","aaa","height=300,width=500,top=50,left=50,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no")
         
            //Child window window object
            console.log(sonwindow);
        }
        function fatherSayHello(){
            alert("hello son!");
        }
</script>

<body>
    <button onclick="testOpen();">Open a new window</button>
</body>

 

Timing task
 
<script type="application/javascript">
        function setTime() {
//            window.setTimeout("alert('hello!')",5000);
            window.setTimeout(sayHello, 5000);
        }
        var sayHello = function () {
            alert("Hello!");
        }
    </script>
</head>
<body>
<button onclick="sayHello();">call sayHello</button>
<button onclick="setTime();">call setTime</button>

 

2. Perform tasks at intervals
   <script type="application/javascript">
     /*
        window.onload = function(){
         window.setTimeout(closeSelf, 1000);
         }
         function closeSelf() {
         var secval = document.getElementById("sec").innerHTML;
         var secint = parseInt(secval);
         document.getElementById("sec").innerHTML = --secint;
         if(secint == 0){
         window.close();
         }
         window.setTimeout(closeSelf, 1000);
         }
      */

        var taskid = 0;
        window.onload = function(){
            //Interval execution task,Interval 1000 ms Execute once
            taskid = window.setInterval(closeSelf, 1000);
        }
        function closeSelf() {
            //Get 10 s 
            var secval = document.getElementById("sec").innerHTML;
            console.log(secval);
            var secint = parseInt(secval);
            console.log(secint);
            //10s reduce
            document.getElementById("sec").innerHTML = --secint;
            if(secint == 0){
                window.close();
            }
        }
          //    4.Clear interval execution task pause
        function stopTask(){
            window.clearInterval(taskid);
        }
              //Continue timing
        function goonTask(){
            taskid = window.setInterval(closeSelf, 1000);
            console.log(taskid)
        }
    </script>
    
<body>
//Payment succeeded, page will be in<span id="sec">10</span>s Then close.
<button onclick="stopTask()">Wait a minute. I'll close myself later</button>
<button onclick="goonTask()">Continue reading seconds, close window</button>
</body>

 

Posted by Blade280891 on Sun, 17 Nov 2019 13:32:13 -0800