Widely supported
The Facebook Messenger extension method is the most compatible way to do this. On the mobile device, it closes the web view, on the desktop it closes the tab (web-openers open in new tabs on the desktop messenger).
Firstly, to whitelist your domain, to be able to use Messenger extensions, use an access token for your application. Use the page_access_token generated for your bot.
curl -X POST -H "Content-Type: application/json" -d '{ "whitelisted_domains":[ "https://petersfancyapparel.com" ] }' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN"
Upload the Messenger SDK to a webview page using video
<script> (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.com/en_US/messenger.Extensions.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'Messenger')); </script>
Then add an event listener to the video element to call the browser close function
<video src="video.ogv" id="myVideo"> video not supported </video> <script type='text/javascript'> document.getElementById('myVideo').addEventListener('ended',myHandler,false); function myHandler(e) { MessengerExtensions.requestCloseBrowser(function success() { }, function error(err) { }); } </script>
IOS only
The only quick and dirty way is to redirect to https://www.messenger.com/closeWindow/?image_url=IMAGE_URL&display_text=DISPLAY_TEXT , which will show the specified image and text before closing the window. Docs about it
For this you would do
window.replace('https://www.messenger.com/closeWindow/?image_url=IMAGE_URL&display_text=DISPLAY_TEXT')