Search code examples
htmlgoogle-chromeiframepdf-viewer

Open PDF from Chrome IFRAME failed with default PDF viewer


The code looks like:

    <iframe pm-attr-iframe class="widget-body" ng-src="{{vm.iframeUrl}}"  sandbox="allow-same-origin allow-popups allow-forms allow-top-navigation">
    (not available)
</iframe>

Click the PDF link inside the iframe, it opens with white content. If right click the mouse and click "Save", it works.

If open the URL to any tab or window, the PDF file rendered with default PDF viewer.

If I add other PDF viewer to Chrome extensions, it always works.

Is it caused by default PDF viewer of Chrome? How to avoid it?


Solution

  • It turns out the sandbox make the iframe lost permission to access the PDF file on Chrome, but all other web browsers do not have this behaviour.

    After remove sandbox="allow-same-origin allow-popups allow-forms allow-scripts", it works.

    <iframe pm-attr-iframe class="widget-body" ng-src="{{vm.iframeUrl}}">
        (not available)
    </iframe>