📅  最后修改于: 2020-10-25 10:50:19             🧑  作者: Mango
重要的是要了解不同浏览器之间的差异,以便按预期方式处理每个浏览器。因此,重要的是要知道您的网页正在运行哪个浏览器。要获取有关您的网页当前正在运行的浏览器的信息,请使用内置的导航器对象。
您可以在网页中使用几个与Navigator相关的属性。以下是名称及其说明的列表。
Sr.No | Property & Description |
---|---|
1 |
appCodeName This property is a string that contains the code name of the browser, Netscape for Netscape and Microsoft Internet Explorer for Internet Explorer. |
2 |
appVersion This property is a string that contains the version of the browser as well as other useful information such as its language and compatibility. |
3 |
language This property contains the two-letter abbreviation for the language that is used by the browser. Netscape only. |
4 |
mimTypes[] This property is an array that contains all MIME types supported by the client. Netscape only. |
5 |
platform[] This property is a string that contains the platform for which the browser was compiled. “Win32” for 32-bit Windows operating systems. |
6 |
plugins[] This property is an array containing all the plug-ins that have been installed on the client. Netscape only. |
7 |
userAgent[] This property is a string that contains the code name and version of the browser. This value is sent to the originating server to identify the client. |
有几种特定于导航器的方法。这是它们的名称和描述的列表。
Sr.No | Methods & Description |
---|---|
1 |
javaEnabled() This method determines if JavaScript is enabled in the client. If JavaScript is enabled, this method returns true; otherwise, it returns false. |
2 |
plugings.refresh This method makes newly installed plug-ins available and populates the plugins array with all new plug-in names. Netscape only |
3 |
preference(name,value) This method allows a signed script to get and set some Netscape preferences. If the second parameter is omitted, this method will return the value of the specified preference; otherwise, it sets the value. Netscape only |
4 |
taintEnabled() This method returns true if data tainting is enabled; false otherwise |
以下JavaScript代码可用于找出浏览器的名称,然后相应地可以向用户提供HTML页面。
Browser Detection Example
成功执行上述代码后,将显示以下输出。
Mozilla based browser
Browser version info : 5.0
(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 41.0.2272.101 Safari / 537.36