Created
August 12, 2016 18:04
-
-
Save sax1johno/b27db2a544c49ce6e2feae543e85be1f to your computer and use it in GitHub Desktop.
Code in NativeScript to overload URL's in a rendered web page and display them in a content-appropriate way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webView = view.getViewById(page, "webView"); | |
if (webView.android) { | |
try { | |
var MyWebViewClient = android.webkit.WebViewClient.extend({ | |
shouldOverrideUrlLoading: function(_webView,interceptedUrl){ | |
console.log('Intercepted Url was ', interceptedUrl); | |
utils.openUrl(interceptedUrl); | |
return true; | |
}, | |
onPageFinished: function(_webView, pageUrl) { | |
loading.hide(); | |
var message; | |
if (!args.error) { | |
message = "WebView finished loading " + args.url; | |
} | |
else { | |
message = "Error loading " + args.url + ": " + args.error; | |
} | |
} | |
}); | |
webView.android.setWebViewClient(new MyWebViewClient()); | |
} catch(e) { | |
alert(e.message); | |
} | |
} | |
webView.url = url; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, much appreciated!
It is worth mentioning that this works on livesync, but crashes upon java compiling at build.
The fix is not to extend a java class directly, but through a reference: