To refer to window property: window.propertyName.
The window object is the topmost object in the object hierarchy, therefore it can be shortened to: propertyname, and window is the default object.
Now try to generate the following output on the browser. See image.
The above can be generated in IE from the following code
< html >
< head >
< title > Start and stop a clock < /title >
< /head >
< body >
< input type="text" size= "60" id="theclock" / >
< script type="text/javascript" >
var setIntervalID = window.setInterval("setClock()",1000);
function setClock()
{
var now = new Date();
document.getElementById("theclock").value=now.toLocaleString();
}
function stopClock()
{
clearIntervalID=window.clearInterval(setIntervalID);
}
< /script >
< button onclick="stopClock()" >Stop< /button >
< /body >
< /html >
Modify the above script so that you can display the clock as the following with only time portion shown See image.
Note the time shall be current local time for both figure above.
In order to output the above, you need to just output the time portion of the local string. To find the Date object and its properties, please refer to the link
http://www.w3schools.com/jsref/jsref_obj_date.asp
The following script will generate three windows using arrays. Firstly it will create a page with a button ‘start to create windows’. When clicked, three windows will appear on the screen in specified locations. See image.
Here is the code
< html >
< head >
< title >Opening and Closing Windows< /title >
< script type="text/javascript" >
var myWindows = new Array();
var windowNo = new Array("Window1", "Window2", "Window3");
var leftPos =[200, 450, 700];
function createWindows()
{
for (i=0; i < 3; i++)
{
var j= i*200;
myWindows[i] = window.open("http://www.montclair.edu/", windowNo[i], "height=200,width=200,left="+leftPos[i])
}
}//end of createWindows
< /script >
< /head >
< body >
< h1 >Open and Close windows< /h1 >
< h2 >Press buttons to open and close windows< /h2 >
< form >
< input type="button" id="createWindowsbtn" value="start to create windows" onclick="createWindows();" >
< /form >
< /body >
< /html >
Refer to the following for window open method
http://www.w3schools.com/jsref/met_win_open.asp
Try to generate several windows on random locations using random number generator we learned.