Add event listener to links loaded in webview? (Titanium Mobile)

寵の児 提交于 2019-12-25 02:28:52

问题


I am working on a sample app using titanium. I have created a webview and loaded a local html as shown below

var webview = Ti.UI.createWebView({ borderWidth:0, paddingRight:10,width:310,top:25, height:210,left:5 });
webview.html = '<div><a href="http://google.com" id="ggle"></a></div>'

is it possible for me to add event listener for the anchor tag specified in the html? if so how? if not please suggest me anyother possible solution.

thanks.


回答1:


Yes you can add your custom event like this:

<div><a href="http://google.com" id="ggle" onclick="Ti.App.fireEvent('openLink', {linkUrl: 'http://google.com'});"></a></div>

And listen to the event in your app.js file:

Ti.App.addEventListener('openLink', function(e){
    Ti.Platform.openURL(e.linkUrl);
});

For complete details Communication Between WebViews and Titanium



来源:https://stackoverflow.com/questions/14856448/add-event-listener-to-links-loaded-in-webview-titanium-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!