Tuesday, March 20, 2007

Javascript Tips

Detecting Browser and Browser Version:

eg:
For internet explorer:
navigator.userAgent.indexOf("msie")!= -1

navigator.appName

navigator.appVersion

Detecting Plugins:

navigator.mimeTypes

eg:navigator.mimeTypes['application/x-shockwave-flash'];
navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin

navigator.plugins["Shockwave Flash"];

To fetch the selected text:

mozilla/opera: window.getSelection().toString()
ie : document.selection.createRange().text

window.onerror Event:

onerror event fires whenever an JavaScript error occurs.
The onerror event is of the window object, a rather unusual object to be attached to. It is attached this way so it can monitor all JavaScript errors on a page, even those in the section of the page.

No comments: