Search code examples
htmlwebviewtitanium

Get URL from remote URL in webview and open it in safari


I have a webview in my application and I also have a website online. I have loaded my website in my webview and when I press a link in my website I want to open that link in Safari and not in my webview, here´s what I have done.

I have my webview:

var webview = Titanium.UI.createWebView({
    url: 'http://www.TEST.com', // dummy url now
    top: 42,
    left: 0,
    width: 310,
    height: 275
});

My HTML file (which I will put online so I will only access it trough my www address):

<!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <link rel="stylesheet" href="style.css">
      <link rel="stylesheet" href="img.css">
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
      <script src="script.js"></script>
    </head>
     <body onload="Ti.API.info('body loaded!');">
      <div id="wrapper">
        <ul class="slide" id="slideOne">
          <li><img src="images/1.jpg" onClick="Ti.App.fireEvent('openlink',{url:'http://www.google.com'})"/></li>
      </div>
    </body>
</html>

And to access the HTML code I have the following code::

Ti.App.addEventListener('openlink', function(e) {
   alert('Ti.App);
   Ti.Platform.openURL(e.url);
});

But nothing happens when I press the image, anyone has a clue why?


Solution

  • You cant do this on a remote web site.

    From this guide, in the Remote web content section:

    You cannot use any Titanium statements within HTML content loaded from a remote host.