If you don't find an answer, please click here to post your question.

Autoplay for Safari 11: Script Example

0 Kudos
Started ‎09-21-2017 by
Modified ‎09-21-2017 by

Autoplay for Safari 11: Script Example

by Community Manager on ‎09-21-2017 12:44 PM (265 Views)

Below is a sample script of a pop-up message you can display on your webpage asking customers to add your site to the allowed list for unmuted autoplay.

 

<script>

 // Detect browser for mac OS safari 11+, then alert a "message" to end user.

 (function() {

   try {

     // Detect if the browser is safari AND if it is running on Mac OS

     var isMacSafari = window.safari !== undefined && !!window.navigator.platform.match(/Mac/);

     if (isMacSafari) {

       // Parse the browser version for use

       var version = parseInt(window.navigator.userAgent.match(/Version\/(\d+)/)[1], 10);

       // If safari version 11+, alert or log a message

       if (version >= 11) {

         // Site owner to decide if alert is the right recommendation

         alert("For optimal playback experience on your Safari browser, enable autoplay for this website by navigating to Safari-> Settings for this web site -> Auto-play: Allow All Autoplay");

       }

     }  

   } catch (e) {}

 })();

</script>