【问题标题】:Using iframe tag in an ionic application在离子应用程序中使用 iframe 标签
【发布时间】:2019-09-15 04:11:40
【问题描述】:

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

我是这样使用html的<iframe>标签的:

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

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

如果您使用&lt;object&gt;&lt;embed&gt; 标签,也会发生同样的情况。

谁能告诉我为什么?

非常感谢!

【问题讨论】:

    标签: html pdf ionic-framework iframe


    【解决方案1】:
    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));
    

    【讨论】:

    • 感谢您的帮助!但是我仍然无法在 ionic 应用程序页面中查看 pdf,因为谷歌文档告诉我关于 pdf 的“预览不可用”。 pdf 可通过 url 'localhost:8100/assets/documents/relation.pdf' 访问,但使用
    猜你喜欢
    • 2017-03-16
    • 2018-07-13
    • 2013-11-12
    • 2018-03-01
    • 1970-01-01
    • 2020-07-14
    • 2016-11-16
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多