After updating my Safari to the latest 14.0.1 version on my macOS 10.14.6 the file selector which would usually come when one clicks onto ‘Choose File’ button, stopped working.

Interesting enough when one drags and drops a file from a Finder window onto the Choose File button, this file will then be selected, but… WTF? Safari 14.0.1 works fine on macOS 10.15.x or on iOS.

Anyhow while I am hoping for Apple to solve this in a future update for macOS 10.14.6 users, I decided to implement a warning on the page of my Free ICS to CSV converter showing only when one opens the page using Safari 14.0.1

So I coded something like the following in php…

if (get_browser_name($_SERVER['HTTP_USER_AGENT']) == 'Safari') {
if (get_browser_plattform($_SERVER['HTTP_USER_AGENT'])) {
echo "Note for Safari 14.0.1 on macOS 10.14.x: 
      Please use another browser…";
}

Whereby… my php functions… get_browser_name($user_agent) and get_browser_plattform($user_agent) calculate as follows:

function get_browser_name($user_agent) {
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/'))
 return 'Opera';
elseif (strpos($user_agent, 'Edge')) return 'Edge';
elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
elseif (strpos($user_agent, 'Safari')) return 'Safari';
elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (strpos($user_agent, 'MSIE') || 
  strpos($user_agent, 'Trident/7')) 
  return 'Internet Explorer';
  return 'Other';
}

and…

function get_browser_plattform($user_agent) {
    if ( strpos($user_agent, '14.0.1') && 
        strpos($user_agent, 'Mac OS X 10_14'))  { 
	return true; 
    } else { 
    	return false;
    }
}
 

I thought first I should check for iPhone or iPad in the $user_agent, this however has still the issue I noticed sometime ago here.

So… I am simply checking for the Safari and the macOS versions, because I actually know through tests that the function is fine on newer or older systems, and I otherwise do not want to make things more complicated for users of other browsers.

Well, I am fine with that solution for the time being. 🖖

PS: Is it me or it is so much difficult currently pasting code text in the editor of WordPress and having it formatted in a decent way?

Spread the love