open link from webview in safari window not working

You must Login before you can answer or comment on any questions.

hi any idea why is this not working ? want to open link in safari window. if i click on link just scroll to the top. thanks for answer

var self = Titanium.UI.currentWindow;
 
var htmlContent = "<a onclick='Titanium.Platform.openURL(\"http://www.google.com\");  return false;' href='#'><img src='../images/logo_small.png'></a>";
 
var webView = Ti.UI.createWebView({
     html: htmlContent      
 
});
 
self.add(webView);

1 Answer

Hi Michal,

Tyr this method, In your html page(test.html)

<html lang="en">
<head> 
    <title> Privacy Policy</title>
 
    <script>
        function openWebLink(input){
            Ti.App.fireEvent('openSafari', {url:input});
        }
    </script>
</head>
 
<body>
    <div>
    <p> Click here to open apple site <a href="#" id="http://www.apple.com/legal/sla/" onclick="openWebLink(this.id);" >http://www.apple.com/legal/sla/</a>.</p>
     </div>
</body>
</html>
in your app.js
Ti.App.addEventListener('openSafari', function(data) 
{ 
    Ti.Platform.openURL(data.url);
});
Hope this helps you.

— answered 8 months ago by Karthi Ponnusamy
answer permalink
1 Comment
  • thanks karthi, but i am not using html page, i am generating html code directly in .js file and assign code to htmlContent variable. can that be problem ?

    — commented 8 months ago by michal machovic

Your Answer

Think you can help? Login to answer this question!