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:
- How would I detect if html contains an url?
- If the url is complete - how do i manage to open it in browser in both Android and iphone?
- 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