JavaScript Window Navigator
JavaScript Window Navigator
The window.navigator object contains information about the visitor's browser.
Window Navigator
window.navigator object can be written without using the window prefix.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <div id="example"></div> <script> txt = "<p>瀏覽器代號(hào): " + navigator.appCodeName + "</p>"; txt+= "<p>瀏覽器名稱(chēng): " + navigator.appName + "</p>"; txt+= "<p>瀏覽器版本: " + navigator.appVersion + "</p>"; txt+= "<p>啟用Cookies: " + navigator.cookieEnabled + "</p>"; txt+= "<p>硬件平臺(tái): " + navigator.platform + "</p>"; txt+= "<p>用戶(hù)代理: " + navigator.userAgent + "</p>"; txt+= "<p>用戶(hù)代理語(yǔ)言: " + navigator.systemLanguage + "</p>"; document.getElementById("example").innerHTML=txt; </script> </body> </html>
WARNING!!!
The information from the navigator object is misleading and should not be used to detect browser versions because:
navigator data can be changed by browser users. Some browsers will recognize errors on test sites. The browser cannot report new operating systems released later than the browser.
Browser detection
Due to navigator Can mislead browser detection, and can be used to sniff different browsers using object detection.
Since different browsers support different objects, you can use objects to detect browsers. For example, you can identify Opera because only Opera supports the property "window.opera".
Example: if (window.opera) {...some action...}