Search code examples
javascriptiossafarismartbanner

Detect iOS smartbanner feature availability


I'm using jQuery Smartbanner (https://github.com/jasny/jquery.smartbanner) for cross mobile OS smart banner support. But I've run on to an issue, that ONLY iOS safari natively supports smartbanner feature, and other iOS browsers - don't. So when i'm just activating this plugin, safari shows me tow smart banners (native and custom), and other browsers - as supposed - one. I've added next check, to make sure user is on iphone/ipad/ipod and safari.

if ( !(/(iPad|iPhone|iPod).*OS [6-7].*AppleWebKit.*Mobile.*Safari/.test(navigator.userAgent)) )
    $.smartbanner()

But this conditional check restricts all iOS mobile browsers, not only Safari. So I've figured out, that i can't simply detect mobile safari in order to not apply smartbanner() plugin specifically on it.

Any tips on detecting iOS Safari specifically?

P.s.: all safari browsers have "Safari" word inside navigator.userAgent


Solution

  • Currently fixed that issue, by adding "Version" word into condition. I found that only safari has this word inside userAgent on iOS (Chrome, for ex. doesn't).

    So final condition looks like this:

    if ( !(/(iPad|iPhone|iPod).*OS [6-7].*AppleWebKit.*Version.*Mobile.*Safari/.test(navigator.userAgent)) )
        $.smartbanner()