JavaScript Window Object Model

Window object

The Window object is the top-level object in the browser object model. All browsers support the window object, which represents the browser window. If the document contains frames, the browser creates a Window object for an HTML document and an additional Window object for each frame.

Window size

window.innerHeight The inner height of the browser window

window.innerWidth The inner width of the browser window

Window common methods

alert("prompt message") displays a dialog with a prompt message and a confirm button
confirm("prompt for input information") displays a dialog box with a prompt message and confirm and cancel buttons
prompt("prompt message", default value ") displays a dialog that prompts the user for input
open("url","name","features") opens a new window with the specified name and loads the document at the given URL
close( ) closes the current window
showModalDialog( ) opens the specified document as a modal window
setTimeout( ) calls the function or evaluates the expression after the specified number of milliseconds
clearTimeout( ) cancels the timer set by the setTimeout method

Dynamic Clock Example

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>动态时钟</title>
	<script type="text/javascript">
       function timer(){
       		var currentDate=new Date();
       		var year=currentDate.getFullYear();
       		var month=currentDate.getMonth()+1;
       		month=checkTime(month);
       		var day=currentDate.getDate();
       		var hour=currentDate.getHours();
       		var hour=checkTime(hour);
       		var minute=currentDate.getMinutes();
       		minute=checkTime(minute);
       		var second=currentDate.getSeconds();
       		second=checkTime(second);
       		
       		var time=year+'-'+month+'-'+day+'  '+hour+':'+minute+':'+second;
       		var mydiv=document.getElementById('result');
 			mydiv.innerHTML=time;
 			setTimeout('timer()',1000);
 			
       }
 	   function checkTime(i){
 	   	    if(i<10){
 	   	    	i='0'+i;
 	   	    }
 	   	    return i;
 	   }



	</script>
</head>
<body onload='timer();'>
	<div id='result'>
	</div>
</body>
</html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981650&siteId=291194637