27

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.

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

Rob
  • 14,746
  • 28
  • 47
  • 65
Brent Nicolet
  • 345
  • 1
  • 5
  • 9
  • 5
    Forget the message, people don't want to be told to use a different browser to access your site. People want content. As long as that is accessible, they won't mind any parallax missing. Edge seems to have issues with fixed backgrounds, causing them to jump up and down on scrolling. I think, however, it's a browser related thing, not a problem of your code. – ROAL Oct 15 '15 at 15:32
  • More reliable way would be to do feature detection rather than browser sniffing. – Rob Oct 15 '15 at 15:32
  • how do i do this feature detection? – Brent Nicolet Oct 15 '15 at 15:35
  • Possible duplicate of [How to detect Safari, Chrome, IE, Firefox and Opera browser?](http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser) – Rob Oct 15 '15 at 15:35
  • 6
    Feature detection seems to be recommended these days, but the concept is flawed. Problem is it's possible for a feature to be implemented but still bugs that mean you can't use it the desired way. So then you have to detect the browser with the specific bug in it to make the page work on that browser. Or is there a better way to work around browser bugs? – Russell Horwood Dec 12 '16 at 10:07

3 Answers3

75

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!');
}
Reda
  • 1,361
  • 10
  • 12
  • 2
    This does NOT work for IE8+. It only works for Edge. – Trolzie Oct 01 '18 at 11:05
  • In MS Edge the XMLHTTPRequest object doesn't raise progress events and there's no good way to do feature detection for this, so that's one reason to use it (and now that it was fixed, I have to do VERSION detection xD) - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12224510/ – Wayne Bloss Jan 03 '19 at 15:48
2

For me better this:

var uA = window.navigator.userAgent,
    isIE = /msie\s|trident\/|edge\//i.test(uA) && !!(document.uniqueID || document.documentMode || window.ActiveXObject || window.MSInputMethodContext),
    checkVersion = (isIE && +(/(edge\/|rv:|msie\s)([\d.]+)/i.exec(uA)[2])) || NaN;

Go run: http://jsfiddle.net/Webnewbie/apa1nvu8/

James Peter
  • 151
  • 2
1

I use these functions, which work even if the user agent is set to something else.

if (document.documentMode) 
{
    console.log('Hello Microsoft IE User!');
}

if (!document.documentMode && window.msWriteProfilerMark) {
    console.log('Hello Microsoft Edge User!');
}

if (window.msWriteProfilerMark) 
{
    console.log('Hello Microsoft User!');
}

And this detects Chredge/Edgium (aka. Anaheim)

function isEdg()
{ 

    for (var i = 0, u="Microsoft", l =u.length; i < navigator.plugins.length; i++)
    {
        if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
            return true;
    }

    return false;
}

And this detects Chromium:

function isChromium()
{ 

    for (var i = 0, u="Chromium", l =u.length; i < navigator.plugins.length; i++)
    {
        if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
            return true;
    }

    return false;
}
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442