Function 如何在appcelerator中调用webview html href onClick中的函数
我在html中有webview,我在每个链接中显示了多个链接,我想调用javascript函数。但是javascript函数没有调用。请帮助解决此问题。提前感谢。 下面是我的代码Function 如何在appcelerator中调用webview html href onClick中的函数,function,webview,href,appcelerator,appcelerator-titanium,Function,Webview,Href,Appcelerator,Appcelerator Titanium,我在html中有webview,我在每个链接中显示了多个链接,我想调用javascript函数。但是javascript函数没有调用。请帮助解决此问题。提前感谢。 下面是我的代码 var win = Ti.UI.createWindow({ backgroundColor : '#fff' }); var webViewTesting = Ti.UI.createWebView({ height : Ti.UI.SIZE, width : Ti.UI.FILL, html : "
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');
}
var win=Ti.UI.createWindow({
背景颜色:“#fff”
});
var webViewTesting=Ti.UI.createWebView({
高度:Ti.UI.SIZE,
宽度:Ti.UI.FILL,
html:“Hi Nice Style By”,
});
添加(webViewTesting);
函数displayUserDetails(){
Ti.API.info('displayUserDetails');
}
您可以在.html中使用Ti.App.firevent
:
<a href="#" onclick="Ti.App.fireEvent('action');">Test</a>
编辑,将代码更改为:
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');
});
var win=Ti.UI.createWindow({
背景颜色:“#fff”
});
var webViewTesting=Ti.UI.createWebView({
高度:Ti.UI.SIZE,
宽度:Ti.UI.FILL,
html:“Hi Nice发型师”
});
添加(webViewTesting);
Ti.App.addEventListener('displayUserDetails',function(){
//做点什么
Ti.API.info(“displayUserDetails”);
});
您可以在.html中使用Ti.App.firevent
:
<a href="#" onclick="Ti.App.fireEvent('action');">Test</a>
编辑,将代码更改为:
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');
});
var win=Ti.UI.createWindow({
背景颜色:“#fff”
});
var webViewTesting=Ti.UI.createWebView({
高度:Ti.UI.SIZE,
宽度:Ti.UI.FILL,
html:“Hi Nice发型师”
});
添加(webViewTesting);
Ti.App.addEventListener('displayUserDetails',function(){
//做点什么
Ti.API.info(“displayUserDetails”);
});
HI Thomas,感谢您的快速回复,我尝试了上述方法,但在我的index.js中,fire event listener没有在我的js文件中启动,请帮助我。是否有可能在index.js文件中我有webview我正在使用html属性,因为我在每个链接中都有多个href链接,我想调用函数我已经更改了答案,你可以试试我发布的新代码吗?嗨,托马斯,谢谢你的快速回复,我已经尝试了上述方法,但在我的index.js中,fire event listener没有在我的js文件中启动,请帮助我。在index.js文件中是否可能我有webview我正在使用html属性,因为我在每个链接中都有多个href链接,我想调用函数我已经更改了答案,你可以尝试我发布的新代码吗?