html - 在离子应用程序中使用 iframe 标签
问题描述
我正在开发一个简单的离子应用程序,我需要在应用程序的特定页面中插入和查看 pdf。
我<iframe>
以这种方式使用了 html 标签:
<iframe width="400" height="600" src="assets/documents/relation.pdf">
</iframe>
但它不起作用(pdf在页面内不可见)。
如果您使用<object>
or<embed>
标签,也会发生同样的情况。
谁能告诉我为什么?
太感谢了!
解决方案
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));
推荐阅读
- python-3.x - 如何更新比较两个字典的键?
- python - 如何将 pexpect 的输出复制到文件中
- python - Python 是否在处理大量数字/列表时遇到问题,或者我的代码有问题?
- c++ - 如何创建一个具有同一类成员的模板类?,在某个时候初始化它的值?,并尽可能避免使用指针
- awk - 仅打印一次“else”语句的条件 awk 命令
- node.js - 使用 animate.css 包解决 npm run serve 上的“无法读取未定义的属性 'unprefixed'”
- php - 当用户订购产品时计数
- amazon-web-services - 无需我注册设备并创建事物或事物类型,我的 iot 设备能否将消息发布到 AWS IoT 核心消息代理?
- r - R 错误:代码返回 1 列而不是 4 列
- facebook - Facebook 信使错误此消息在此应用程序上不可用