Object Oriented JavaScipt Programming
Now let us see how to get information about different things - like find the time. Or to know what browser the user is using. Or his/her resolution. Or to find the answer to life, the universe and everything.
Lets see how to find the time.
var today = new Date() alert("Hour : "+today.getHours() + "\nMinutes : "+today.getMinutes()+ "\nDay : "+today.getDate()+"\nMonth : "+today.getMonth()+ "\nYear : "+today.getYear())
Now lets see how to find the browser, resolution and other such personal stuff.
The most easiest way to find the browser is
alert("Browser : "+navigator.appName)
But in most cases this is not enough. You have to use other elements like 'navigator.userAgent' to find the correct browser and its version. 'navigator.userAgent' also has information about your operating system which make it extremely useful. One method to do this is...
var str = navigator.userAgent.toString() array = str.split("; ") var OS = array alert("Operating System : "+OS)
Finding Resolution is easy - 'screen.width' gives the width while 'screen.height' gives the screen height.
Want to find the answer to life, the universe and everything? Search for it in Google - the answer is 42.
Try out what you have learned. Please remember that diffrent browsers may give different values for some variables.blog comments powered by Disqus