Download PDFs in Cordova InAppBrowser (3.1.0)
My result is now, that inAppBrowser by default isn't capable of handling Downloads at all and doesn't even process links with a file suffix like ".pdf".
a) So one workaround is to open the file in Google Docs by rewriting the link. This works because it's no more a PDF Document, but an external link:
https://docs.google.com/viewer?url=https://www.example.com/yourOnlinePdfDocument.pdf
b) Use the "beforeload" event to decide which browser to use before the link is further processed:
- var app = {
- [...]
- _launchWebApp: function () {
- // Set global variables:
- // previousUrl = null;
- // Open URL in inappbrowser:
- var webAppWindow = cordova.InAppBrowser.open(this.config.webAppUrl, '_blank', 'location=no,beforeload=get,zoom=no,toolbar=no,enableViewportScale=yes');
- // Register events:
- webAppWindow.addEventListener('beforeload', this.onBeforeLoad.bind(this, webAppWindow), false);
- },
- /**
- *
- */
- onBeforeLoad: function(webAppWindow, params, callback){
- // Special handling of downloads. InAppBrowser doesn't handle them
- // so we have to manually preprocess and open in system browser:
- if(params.url.match(".pdf")){
- cordova.InAppBrowser.open(params.url, '_system');
- } else {
- // Default handling:
- callback(params.url);
- }
- },
Julian Pustkuchen, M. Sc. Wirtschaftsinformatik ist passionierter Software- & Webentwickler mit den Schwerpunkten Softwaredesign, Objektorientierung sowie Usability- & Ablaufoptimierung bei webks. Ein weiterer Schwerpunkt ist die Entwicklung im CMS Drupal.
Entwickelt Julian gerade keine Software, fährt er Ski, Mountainbike, spielt Badminton, segelt oder verbringt Zeit mit Freunden.
Dieser Blog dient als sein "öffentlicher Notizblo(ck/g)".
Euch gefällt mein Blog?
Vielleicht hilft mir auch ein Buch, euch zukünftig (noch) bessere Artikel zu bieten? (Amazon Wunschliste)
Gerne bewerte ich auch ab und zu einmal unabhängig ein Produkt.
Ich freue mich über jede Art der Unterstützung in Form von Kommentaren, Lob oder Kritik.
Auf zum Kontaktformular!
Zu meinem Google+ Profil
Webbasierte Lösungen? Machen wir!
webks: websolutions kept simple
http://www.webks.de
Tags in Blogeintrag - Kategorie
Dir hat dieser Beitrag viel Zeit und Nerven gespart?
Dann freue ich mich über jede kleine Anerkennung:
Oder du suchst weitere professionelle Unterstützung?
Dann bietet dir unser webks.de Softwareentwickler-Team professionelle Dienstleistungen im Web-Development und der Drupal CMS Entwicklung!
Kommentare
Kommentar hinzufügen