当前位置:网站首页>Navigator object

Navigator object

2022-06-24 18:35:00 Brother Mengfan

1、 What is? navigator object

navigator Object contains information about the browser .

see navigator Object all information :
console.log(navigator);
Let's take the determination of whether a plug-in is installed in the browser as an example , To explain its usage .
stay navigator Among the many properties of the object , There is an attribute called Plugins, The plug-in information is stored inside , Through the following
View by :
console.log(navigator.plugins);
Next, by encapsulating a method , To determine whether a plug-in is installed , If installed, return to true, Otherwise return to false.
    <script>
        function hasPlugin(name) {
            name = name ? name.toLocaleLowerCase() : '';
            console.log('name = ' + name);
            var plugins = navigator.plugins;
            for (var i = 0; i < plugins.length; i++) {
                //console.log(typeof plugins[i]);
                console.log(plugins[i].name);
                return plugins[i].name.toLocaleLowerCase().indexOf(name) !== -1 ? true : false;
            }
        }
        var r = hasPlugin('pdf');
        console.log(r);
    </script>
stay navigator There is another object called userAgent Attributes are more commonly used . It is generally used to obtain browser information .
This property returns the message sent by the client to the server user-agent The value of the head .
The following code can determine which terminal the user opens the page , Realize jump
原网站

版权声明
本文为[Brother Mengfan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211333166971.html

随机推荐