在离子应用程序中使用iframe广告代码

时间:2019-04-25 16:50:13

标签: html pdf ionic-framework iframe

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

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

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

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

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

谁能告诉我为什么?

非常感谢您!

1 个答案:

答案 0 :(得分:0)

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));