← Snippets - Script

Smartbanner for Newer iPads

Apple changed the userAgent (what smartbanner.js checks) for newer iPads to not have “iPad” in the returned value. Newer iPad iOS defaults to a desktop user agent, so smartbanner sees it as Mac desktop Safari. Users can change that setting on their devices, but that’s not a practical solution for our clients.

If a client really complains about it, this fix will do the trick until smartbanner.js is updated by the people who maintain it.

Implementation

  1. Open src/scripts/plugins/smartbanner.js
  2. On line 77, replace
if (/iPhone|iPad|iPod/i.test(window.navigator.userAgent)) {
  return 'ios';
} else if (/Android/i.test(window.navigator.userAgent)) {
  return 'android';
}

with this:

var maxTouchPoints = window.navigator.maxTouchPoints;
var userAgent = window.navigator.userAgent;

if (/Android/i.test(userAgent)){
  return 'android';
} else if ((maxTouchPoints && maxTouchPoints > 0) || /iPhone|iPad|iPod/i.test(userAgent)) {
  return 'ios';
}