Handle file downloads (PDF, DOC, etc.) in PhoneGap HTML Code as system file download dialog (like in browser)

Quelle: http:/pixabay.com/de/monitor-pixabay-website-93962/ (CC0 Public Domain)

It cost me several minutes to find out how to create a file download link in PhoneGap that lets the user download the file like a normal browser (Phones download dialog).

What does not work?

Use a normal link - nothing happens!
Use the inAppBrowser - Files are not handled by it!

What works?

Use a javascript window.open event with "_system" as target.
For example in DrupalGap:

  1. return '<a data-role="none" class="ui-btn" onclick="javascript:window.open(\'' + drupalgap_image_path(row.path) + '\', \'_system\', \'location=yes\');">' + row.rowtitle + '</a>';

So what you simply need is:

  1. onclick="javascript:window.open(\'http://www.example.com/mypdf.pdf\', \'_system\', \'location=yes\');"

And the file download in your PhoneGap / DrupalGap App will work like expected!

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Weitere Informationen über Formatierungsoptionen