Unity: WebGL Add a Share Button


Part 1. Preparation

  • For desktop the results are only copied to clipboard
  • For mobile the native browser Share popup is shown

Part 2. JavaScript bridging

  • As with everything else in the JS world, there are multiple ways to copy the data to the clipboard. In order to get the maximum coverage we will use modern Navigator Clipboard API with the fallback to textArea
  • In order to trigger the share popup on mobile devices we will use Navigator Share API. Identifying the mobile device is not an easy task and the approach here relies on the user_agent string





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store