Other common methods of Window object

open() method

  • Function: Open a new browser window.

  • Syntax: var winObj = window.open([url][,name][,options]);

  • Description: Parameters can Dispensable. If no parameters are specified, a tabbed window is opened (size is maximized).

  • Parameters:

    • url: Which file is to be displayed in the new window. url can be an empty string, indicating that an empty page is displayed.

    • name: The name of the new window. This name is used for the target attribute of the tag.

    • options: The specifications of the window.

#Oth: The width of the new window

# Height: The height of the new window

LEFT:

# Top: The distance on the new window distance on the screen

# Menubar: Whether the menu bar is displayed, the value: yes, no

Toolbar: Whether the toolbar is displayed.

Location: Whether to display the address bar.

status: Whether to display the status bar.

scrollbars: Whether the scroll bar is displayed, you cannot omit the S letter.

4. Return value: Return a variable of Window object, you can track the window through this name. winObj has all the properties and methods of the window object.

Note:

onload event: This event (condition) is triggered only when the web page is loaded and all contents of the indicator mark are loaded. . Use the onload event attribute to call the JS function. The onload attribute is only available in the body tag.

onclick event: When clicked, call the JS code. All HTML tags have this event attribute.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script type="text/javascript">
        function init(){
        window.open("","php.cn") 
        }
        </script>
    </head>
    <body onload="init()">
    </body>
</html>


Delayer method——setTimeout()

setTimeout()

  • Function: Set a delayer, in other words: Once the time is up, execute the JS code once.

  • Syntax: var timer = window.setTimeout(code,millisec)

  • Parameters:

                      code: is any legal JS code, usually a JS function. The function should be placed in quotes.

Example: Window.Settimeout ("Close ()", 2000)

For example: Window.Settimeout (init, 2000); // The function address of the function is not required. If parentheses are added, the execution result of the function is passed to the method.

                               millisec: millisecond value. 1 second = 1000 milliseconds

  • Return value: Returns the id variable of a delayer. This id variable is used for clearTimeout().

clearTimeout()

  • Function: Clear the delayer id variable

  • Syntax: window.clearTimeout(timer)

  • Parameters: timer is the id variable of the delayer set by setTimeout().

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script type="text/javascript">
        function init(){
        //打开一个新窗口
        var win=window.open();
        win.document.write("欢迎来到php.cn") ;
        //新窗口2秒后关闭
        win.setTimeout("window.close()",2000);
        }
        </script>
    </head>
    <body onload="init()">
    </body>
</html>


##Timer method

setInterval()

  • Function: Set a timer. Timer, execute JS code repeatedly (periodic).

  • Syntax: var timer = window.setInterval(code, millisec)

  • Parameters:

code: is any legal JS code, usually a JS function. The function should be placed in quotes.

Example: Window.SetInterVal ("Init ()", 2000)

Example: Window.SetInterval (Init, 2000); // pass the function address, so no parentheses are needed. If parentheses are added, the execution result of the function is passed to the method.

                   millisec: millisecond value. 1 second = 1000 milliseconds

  • Return value: Returns the id variable of a timer. This id variable is used for clearInterval().

clearInterval()

  • Function: Clear the timer id variable

  • Syntax: window.clearInterval(timer)

  • Parameters: timer is the id variable of the timer set by setInterval().

Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> function init(){ window.open("","php.cn") } </script> </head> <body onload="init()"> </body> </html>
submitReset Code