Yes, although you have to check which browser is in use. The code from MSIE is different than for Mozilla-based browsers. Not sure about code for Apple's Safari. Probably Mozilla-compatible, but would need to be checked.
Lots of sites have help with this, so pointless to write code here for you.
You might start with the JavaScript FAQ section at
http://www.irt.org