Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Detect links in webview with 'beforeload'?

$
0
0

Hi (using Appcelerator studio 4.0.0 GA developing for both Android + iphone)

I am trying to make a web view displaying remote images within the web view and to open pdf:s and other links in the browser (the latter works only with iphone, not Android so far.)

This is a sample of my remote html (json from Wordpress) (so yes I have access to <head> and can configure that:

html=
 
"<p><a href='http://www.oursite.se'><img src='wp-content/uploads/2014/10/image.png'></a>
<br>
Click <a href='http://www.oursite.se/wp-content/uploads/2015/04/myPdf.pdf'> to download pdf</a>"
The structure might change but that is out of my control so I will settle for just covering the examples here. So question is:
  1. How would I detect if html contains an url?
  2. If the url is complete - how do i manage to open it in browser in both Android and iphone?
  3. How do I detect a part of url - ”wp-content/uploads….” and put ”http://www.oursite.se” in front of it?

The code so far:

var wp_url;
 
webView.addEventListener('beforeload',function(e){
 
if (e.url.indexOf("/wp-content/uploads") !== -1) {
var part_url = "http://www.oursite.se" + e.url;
wp_url = encodeURIComponent(part_url);
//Ti.Platform.openURL(url);
webView.stopLoading();
 
//eventlist
webView.addEventListener('click', function(e) {
Titanium.Platform.openURL(wp_url);
webView.stopLoading();
});
}
});

Any ideas on how to open most kinds of links in browser OR to display remote images within web view? Best regards /Tove


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>