首页 > 解决方案 > 在离子应用程序中使用 iframe 标签

问题描述

我正在开发一个简单的离子应用程序,我需要在应用程序的特定页面中插入和查看 pdf。

<iframe>以这种方式使用了 html 标签:

<iframe width="400" height="600" src="assets/documents/relation.pdf">
</iframe>

但它不起作用(pdf在页面内不可见)。

如果您使用<object>or<embed>标签,也会发生同样的情况。

谁能告诉我为什么?

太感谢了!

标签: htmlpdfionic-frameworkiframe

解决方案


install cordova plugin add org.apache.cordova.inappbrowser In case of android we use GoogleDocs to open pdf file as by default android browser does not support pdf viewing. iOS is smart enough to handle pdf itself as usual smile .

Example :

$scope.view_link = function (url, link_type) {
            if (ionic.Platform.isAndroid()) {
                if (link_type !== undefined && link_type !== null) {
                    if (link_type.toLowerCase() !== 'html') {
                        url = 'https://docs.google.com/viewer?url=' + encodeURIComponent(url);
                    }
                }
            }
            var ref = window.open(url, '_blank', 'location=no');
        }
for more https://github.com/apache/cordova-plugin-inappbrowser/blob/8ce6b497fa803936784629187e9c66ebaddfbe1b/doc/index.md

if you are looking for iframe try something like this

<iframe ng-src="{{pdfurl}}" style="width:100%; height: 100%;"></iframe>
in controller..

$scope.pdfurl =$sce.trustAsResourceUrl('https://docs.google.com/viewer?url=' + encodeURIComponent($scope.pdf));

推荐阅读