首頁 > web前端 > html教學 > 用JavaScript如何找到網頁瀏覽器的名稱和版本?

用JavaScript如何找到網頁瀏覽器的名稱和版本?

王林
發布: 2023-09-19 17:37:02
轉載
907 人瀏覽過

用JavaScript如何找到網頁瀏覽器的名稱和版本?

要尋找網頁瀏覽器的名稱和版本,您需要嘗試以下程式碼 -

範例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

<html>

   <head>

      <title>Browser Detection Example</title>

   </head>

   <body>

      <script>

         <!--

            var userAgent = navigator.userAgent;

            var opera = (userAgent.indexOf(&#39;Opera&#39;) != -1);

            var ie = (userAgent.indexOf(&#39;MSIE&#39;) != -1);

            var gecko = (userAgent.indexOf(&#39;Gecko&#39;) != -1);

            var netscape = (userAgent.indexOf(&#39;Mozilla&#39;) != -1);

            var version = navigator.appVersion;

 

            if (opera) {

               document.write("Opera based browser");

               // Keep your opera specific URL here.

            }

            else if (gecko) {

               document.write("Mozilla based browser");

               // Keep your gecko specific URL here.

            }

            else if (ie) {

               document.write("IE based browser");

               // Keep your IE specific URL here.

            }

            else if (netscape) {

               document.write("Netscape based browser");

               // Keep your Netscape specific URL here.

            } else {

               document.write("Unknown browser");

            }

            // You can include version to along with any above condition.

            document.write("<br /> Browser version info : " + version );

         //-->

      </script>

   </body>

</html>

登入後複製

以上是用JavaScript如何找到網頁瀏覽器的名稱和版本?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板