Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26768] Android : Beforeload event not working with PDF links on Android

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2019-03-20T18:04:05.000+0000
Affected Version/sRelease 7.5.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterAminul Islam
AssigneeGary Mathews
Created2019-01-25T18:01:42.000+0000
Updated2019-03-20T18:04:09.000+0000

Description

Hello, We have in our application a webview which is loading some links that redirect the user to some PDF files. We know that the Android browser has some issues with PDFs and as a workaround, we use the beforeload event to catch the URL and open the PDFs using other means. The problem that we see is that the event is only being triggered using an emulator. If we switch to a physical device (we tried on a Pixel 1 and on a Galxy S9) the event is not triggered but ONLY with the links that redirect the user to a PDF. If the link sends the user to a regular html file it works as expected. Test Code:
$.index.open();

function init(){
    var webUrl = '<html><head></head><body><a href="https://www.apple.com/support/products/pdf/applecare_ipod_t_and_c_11182003.pdf">Open PDF
    	</a><br><a href="https://www.google.com">Open regular url</a></body></html>';
    $.webView.html = webUrl;
}

init();

$.webView.addEventListener('beforeload', function(_evt){
    alert(_evt.url);
});
Test Environemnt :
Operating System
  Name                        = Mac OS X
  Version                     = 10.13.6
  Architecture                = 64bit
  # CPUs                      = 4
  Memory                      = 8589934592

Node.js
  Node.js Version             = 10.14.1
  npm Version                 = 6.4.1

Titanium CLI
  CLI Version                 = 5.1.1

Titanium SDK
  SDK Version                 = 7.5.0.GA
  SDK Path                    = /Users/user/Library/Application Support/Titanium/mobilesdk/osx/7.5.0.GA
  Target Platform             = android
Please take a look on attached screenshot.

Attachments

FileDateSize
Screenshot_20190125-231435.jpg2019-01-25T18:01:38.000+000054011
Screenshot_20190125-231442.jpg2019-01-25T18:01:39.000+000075896

Comments

  1. Gary Mathews 2019-02-05

    Since 7.5.0 the onlink event is available. They can catch PDF links like so:
       let window = Ti.UI.createWindow(),
           webView = Ti.UI.createWebView({
               html: '<html><head></head><body><a href="https://www.apple.com/support/products/pdf/applecare_ipod_t_and_c_11182003.pdf">Open PDF</a><br><a href="https://www.google.com">Open Google</a></body></html>',
               onlink: function (e) {
                   if (e.url.endsWith('.pdf')) {
                       alert('PDF: ' + e.url);
                       return false; // do not open link
                   }
                   return true; // open link
               }
           });
       window.add(webView);
       window.open();
       

JSON Source