0

I have a WebApp and it works alright in both Android and iOS environments. The problem is, in one of the screens, the WebApp generates (and displays) a PDF file, which should be shareable through Email, WhatsApp, Telegram, etc.

Android does allow the share option in the standalone display mode, but iOS just doesn't. I need to know if there's any way I can actually exit the WebApp mode into plain good-old-browser mode when opening the pdf file, so that the user can actually share it with his/her contacts through the browser's native share dialog.

These are the contents of the manifest.json file

{
    "name": "Test App",
    "short_name": "TestApp",
    "icons": [
        {
            "src": "/icon-192x192.png",
            "sizes": "192x192",
            "type": "image/png"
        },
        {
            "src": "/icon-512x512.png",
            "sizes": "512x512",
            "type": "image/png"
        }
    ],
    "start_url": "https://example.com?a2hs=1",
    "scope": "/",
    "display": "standalone",
    "orientation": "portrait",
    "background_color": "#000000",
    "theme_color": "#000000"
}

So far, I've tried:

  1. using <a href="test.pdf" target="_blank">Display PDF</a> in the pdf link.

  2. using javascript to force-open a new window:

<a href="test.pdf" id="pdf">test</a>
<script>
$(function(){
    $('#pdf').click(function(e){
        e.preventDefault();
        window.open($(this).attr('href'), '_blank');
        return false;
    });
});
</script>

None of those solutions worked out.

Also, I tried changing the display: property in the manifest.json file to minimal-ui - that does allow to share the file/url but that removes the WebApp look & feel, so it's not an option.

Any ideas? Thanks!

abraham
  • 46,583
  • 10
  • 100
  • 152
Andres SK
  • 10,779
  • 25
  • 90
  • 152

1 Answers1

0

I managed to find a solution. I created this alias subdomain:

pdf.example.com

Then, I linked the pdf to the alias subdomain:

<a href="https://pdf.example.com/test.pdf">Display PDF</a>

iOS recognizes this as another server, so it automatically forces the load of the file in a new tab in Safari, exiting the current standalone mode of the webapp.

Andres SK
  • 10,779
  • 25
  • 90
  • 152