如何检测IE和Edge浏览器? [英] How do I detect IE and Edge browser?

查看:315
本文介绍了如何检测IE和Edge浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在IE或Microsoft Edge中使Parallax正常工作。我查看了论坛,但没有找到问题的解决方案。我现在想出了一个解决方案。如果用户使用IE或Edge,我想显示一条消息。我不知道如何检测出正在使用的浏览器是一个还是其中之一。

Can't get Parallax working properly in IE or Microsoft Edge. I've looked in forums and haven't found a solution to the problem. I've come up with hopefully a solution for now. I want to make a message appear if the user is using IE or Edge. Not sure how I can detect that the browser being used is one or the either.

以下是我正在尝试使用的一些javascript代码:

Here is some javascript code I'm trying to work with:

<script src="https://github.com/ded/bowser/blob/master/src/bowser.js"></script>

    // Determine Browser Used
browser = require('bowser').browser; becomes browser = require('bowser');
if (bowser.msie || bowser.msedge) {
  alert('Hello Microsoft User');
}

如果有更好的解决方案,我们将不胜感激。

Any help would be appreciated or if there is a better solution.

http://peaceandplentyinn.mybnbwebsite.com

推荐答案

我怀疑你真的需要检测浏览器。但无论如何它都是这样(不需要使用库):

I doubt you really need to detect the browser. But here it is anyway (don't really need to use a library):

// detect IE8 and above, and edge
if (document.documentMode || /Edge/.test(navigator.userAgent)) {
    alert('Hello Microsoft User!');
}

这篇关于如何检测IE和Edge浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆