Reputation: 57
I have webview in the html i have showing the multiple links in each link i want to call the javascript function.But the javascript function is not calling please help how to resolve this.Thanks in advance. below is my code.
var win = Ti.UI.createWindow({
backgroundColor : '#fff'
});
var webViewTesting = Ti.UI.createWebView({
height : Ti.UI.SIZE,
width : Ti.UI.FILL,
html : "<html><body><p>Hi Nice Hair Style By <a href='#' onclick='displayUserDetails();'>Raju</a><a href='#' onclick='displayUserDetails();'>Jon Hills</a></body></html>",
});
win.add(webViewTesting);
function displayUserDetails(){
Ti.API.info('displayUserDetails');
}
Upvotes: 0
Views: 496
Reputation: 1154
You can use Ti.App.fireEvent
, in your .html :
<a href="#" onclick="Ti.App.fireEvent('action');">Test</a>
Then, in your index.js for example :
Ti.App.addEventListener('action', function(){
//do something
});
edit, change your code to :
var win = Ti.UI.createWindow({
backgroundColor : '#fff'
});
var webViewTesting = Ti.UI.createWebView({
height : Ti.UI.SIZE,
width : Ti.UI.FILL,
html : '<html><body><p>Hi Nice Hair Style By <a href="#" onclick="Ti.App.fireEvent('displayUserDetails');">Raju</a><a href="#" onclick="Ti.App.fireEvent('displayUserDetails');">Jon Hills</a></body></html>"
});
win.add(webViewTesting);
Ti.App.addEventListener('displayUserDetails', function(){
//do something
Ti.API.info("displayUserDetails');
});
Upvotes: 2