opera object
Supports some Opera specific methods.
The opera object is commonly used for browser detection.
Syntax:
Properties that reference the object:
| window.opera |
Possible members:
Methods:
buildNumber | Returns the build number of the browser in Opera. | ||||||
collect | Tries to initiate the JavaScript garbage collection. | ||||||
postError | Prints each argument as a separate message to the Error Console. | ||||||
version | Returns the version number of the browser in Opera. |
Example HTML code 1:
This example illustrates the use of the opera object:
|
||||
<head> <script type="text/javascript"> function IsOpera () { if (window.opera) { alert ("Your browser is Opera"); } else { alert ("Your browser is not Opera"); } } </script> </head> <body> <button onclick="IsOpera ();">The browser is opera?</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example shows how to detect the user's browser:
|
||||
<head> <script type="text/javascript"> function DetectBrowser () { var browser = "Unknown browser"; if (window.opera) { browser = "Opera"; } else { if (navigator.appName.toLowerCase () == "microsoft internet explorer") { browser = "Internet Explorer"; } else { var agent = navigator.userAgent.toLowerCase (); if (agent.search ("firefox") > -1) { browser = "Firefox"; } else { if (agent.search ("safari") > -1) { if (agent.search ("chrome") > -1) { browser = "Google Chrome"; } else { browser = "Safari"; } } } } } alert (browser); } </script> </head> <body> <button onclick="DetectBrowser ();">Detect Browser!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
External links:
User Contributed Comments