下载属性在Phonegap应用中不起作用 [英] Download attribute not working in Phonegap app

查看:96
本文介绍了下载属性在Phonegap应用中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是我的第一个混合应用程序(我已经在Google Play商店和Apple Store上都发布了应用程序).我的目标平台是Android.我不确定会支持哪些版本,如果以后决定发布此想法,我将稍后确定.我正在使用Phonegap Build.

我在使A元素的HTML Download属性工作时遇到了一些麻烦.这就是我所拥有的:

<a download href="http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2014/4/11/1397210130748/Spring-Lamb.-Image-shot-2-011.jpg">Lamb</a>

如果我删除了下载属性,则图像会在我的phonegap应用(Android)中打开.有了它,什么也没发生.至少在Chrome中也能正常工作.有什么想法吗?

解决方案

@Robbert,
我在这个论坛上回答了很多 Cordova/Phonegap 问题,例如很多志愿者.因此,您可能会发现此常见问题解答很有用.

通过此常见问题解答,您想了解#5-Phonegap不是 Webkit for Developers 是一本好书.

我引用

不同的端口可以具有不同的焦点. Mac端口的重点是在浏览器和OS之间进行划分,并引入了Obj-C和C ++绑定,以将渲染器嵌入到本机应用程序中. Chromium的重点完全在浏览器上. QtWebKit提供了其端口,供应用程序在其跨平台GUI应用程序体系结构中用作运行时或呈现引擎.

要清楚一点,Phonegap使用一个名为 webview (适用于Android,以及其他平台上的类似产品).当前的版本基于Chromium的"webkit",但以前它基于旧版本的Android"webview"-已经存在了很多年.但是,即使使用您要查找的属性也可能不可用.

最好的起点是 caniuse.com .搜索下载显示,大多数情况下支持download,但IE,Safari和Opera缺少.否则,它似乎可用,但仅适用于4.4之后的Android.看着我的注释,这似乎与Android开始使用Chromium的Webkit,而不使用过时的Webview库—如我之前所说.

可能的解决方案

@jcesarmobile暗示您可以使用

_OR _

您可以尝试另一个可能具有您要查找的属性的Webview库 -例如人行横道.

目前, crosswalk 仅支持Android,但也有一些Beta版本,您也可以尝试在存储库中.而且,如果您的目标平台是iOS,请改用 WKWebview .

注意,标准的Webview库已经在您的移动设备上,人行横道是单独的,至少会为您的应用程序增加20 MB.

This is not my first hybrid app (I've published apps on both Google Play Store and Apple Store). My target platform is Android. I'm not sure which versions will be supported, I will determine that later if I decide to publish this idea at all.. I'm using Phonegap Build.

I'm having some trouble getting the HTML Download attribute of the A element to work. Here's what I have:

<a download href="http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2014/4/11/1397210130748/Spring-Lamb.-Image-shot-2-011.jpg">Lamb</a>

If I remove the download attribute, the image opens in my phonegap app (Android). With it, nothing happens though. Works fine in at least Chrome, too. Any ideas?

解决方案

@Robbert,
I answer alot of Cordova/Phonegap questions like alot of volunteers on this forum. As such, you might find this FAQ useful.

From this FAQ, you want to be aware of #5 - Phonegap is not a webserver or a webbrowser. This is common mistake. It is true you can use your webbrowser to test you pages, but don't be fooled into thinking that all webbrowsers are the same. As Paul Irish likes to remind use "Not all webbrowser are equal". His article Webkit for Developers is a good read.

I quote

Different ports can have different focuses. The Mac port’s focus is split between Browser and OS, and introduces Obj-C and C++ bindings to embed the renderer into native applications. Chromium’s focus is purely on the browser. QtWebKit offers its port for applications to use as a runtime or rendering engine within its cross-platform GUI application architecture.

To be clear, Phonegap uses a library called webview (with Android, and similar on other platforms). The current incarnation is based on Chromium's "webkit", but previously it was based on an old version of Android "webview" - which was around for years. However, even with the attribute you are looking for may not be available.

The best was place to start is caniuse.com. A search for download shows that download is mostly supported, but missing is IE, Safari, and Opera. Otherwise, it appears it is available, but only for Android after 4.4. Looking at my notes this appears to coincide with Android starting to use Chromium's webkit, and not the dated webview library — as i stated before.

Possible Solutions

As @jcesarmobile alluded to you can use

_OR_

You can try another webview library that might have the attribute you are looking for - like crosswalk.

At this time, crosswalk only supports Android, but there are also a few beta version you can also try that are in the repository. And, if your target platform is iOS, then use WKWebview instead.

NOTE the standard webview library is already on your mobile device, crosswalk is separate and will add at least 20megabytes to your app.

这篇关于下载属性在Phonegap应用中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆