Trigger image map click event from a webview

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

Hi everyone. I'm trying to trigger a click event from an image map elementin Titanium but the event isn't triggered. What i'm missing.

I have the html file

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Left view</title>
</head>
 
<script type="text/javascript">
 
function horn_click() {
    Titanium.App.fireEvent('hornCLick',{
        param:'customParam'
        });
}
 
</script>
 
<body>
 
    <img src="../images/left.png" alt="Left view" usemap="#contents"  style="width:100%; height:100%;"/>
 
    <map name="contents">
        <area shape="rect" coords="160, 70, 241, 151"  alt= "Horn" onclick="horn_click()">
    </map> 
 
</body>
 
</html>
And id the app.js i have
Ti.App.addEventListener('hornClick', function(data) {
        alert ('Horn Click for param'+data);
    });
What i'm doing wrong ? Also i tried onclick event on simple element like <p> but event isn't triggered. Thanks in advance.

3 Answers

your

function horn_click() {
    Titanium.App.fireEvent('hornCLick',{
        param:'customParam'
        });
}
'hornCLick' is incorrectly cased. It should be 'hornClick'

Yes thanks, i saw that i corrected but still not working. The problem is accesing Titanium.App from the external script from the html. An alert in horn_click function is trigered but Titanium.App.fireEvent('hornCLick') not.

hi lonut,

this is very common problem of firing the event from the script and the solution is to use jQuery in the script so you can fire event from anywhere...

Your Answer

Think you can help? Login to answer this question!