Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
How to detect older versions of iOS and prevent a script from loading

Our company recently decided to stop support for iOS 12.3 and below. However a small fraction of users are still on older devices that do not support newer JavaScript operators or syntax.

In order to prevent our script from affecting these users we are looking for ways to stop our script from loading if iOS v12.3 or below is detected.

Our JS code is loaded onto client websites via script tags like so:

<script src="exampledomain.com/example.js"></script>

Our first idea was to detect the useragent like this post but there are some problems with this approach.

  • It is strongly advised against for several reasons outlined here

  • Detecting the user agent within our script means that it still loads and throws errors when iOS <12.3 encounters syntax it cannot handle.

  • Detecting the user agent using conditional javascript on our client websites before loading our script is a possibility but difficult to maintain and not ideal for our customers.

Another option is to point the src of our script element to a script that can detect the UA and serve different versions of our script. However our script is time sensitive and the additional time it takes to make 2 requests instead of 1 is something we would like to avoid.

Lastly it is also possible to detect iOS versions without using the useragent by specifically targetting features that are not supported. For example using the nullish coalescing operator (??) in a try catch statement could indicate that the device is below iOS 12.3. But this method also relies on running JavaScript directly on the client website or doing multiple requests.

I would like to know if there are alternative methods we have not considered. Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This code snipped detects iOS version, so you can manage the scripts from backend side:

function getIOSVersion() {
    const ua = navigator.userAgent;
    if (/(iPhone|iPod|iPad)/i.test(ua)) {
        return ua.match(/OS [\d_]+/i)[0].substr(3).split('_').map(n => parseInt(n));
    }
    return [0];
}

If you do not want to use UserAgent you can use the information of the platform the browser is compiled:

function getIOSVersion() {
    const ua = navigator.platform;
    if (/(iPhone|iPod|iPad)/i.test(ua)) {
        return ua.match(/OS [\d_]+/i)[0].substr(3).split('_').map(n => parseInt(n));
    }
    return [0];

}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!