views:

38

answers:

1

I'm a bit of a noob, but I tried all of the obvious things. Perhaps my javascript is just terrible and that's why, but onmousedown = func; doesn't work. etc.

    function performCommand(event)
{
    /*removed*/
//It reaches this point
        document.body.onclick = function() { 
        //Never reaches this point
/*removed*/
    }
}
A: 

https://developer.mozilla.org/en/DOM/element.onclick

Summary

The onclick property returns the onClick event handler code on the current element.

Syntax

element.onclick = functionRef;

where functionRef is a function - often a name of a function declared elsewhere or a function expression. See Core JavaScript 1.5 Reference:Functions for details.

Example

<!doctype html>
<html>
<head>
<title>onclick event example</title>
<script type="text/javascript">
function initElement()
 {
 var p = document.getElementById("foo");
 // NOTE: showAlert(); or showAlert(param); will NOT work here.
 // Must be a reference to a function name, not a function call.
 p.onclick = showAlert;
 };

function showAlert()
 {
 alert("onclick Event detected!")
 }
</script>
<style type="text/css">
#foo {
border: solid blue 2px;
}
</style>
</head>
<body onload="initElement()";>
<span id="foo">My Event Element</span>
<p>click on the above element.</p>
</body>
</html>

Or you can use an anonymous function, like this:

p.onclick = function() { alert("moot!"); };

(From the MDC @ cc-by-sa.)

Aviral Dasgupta
That's still not working. I don't know why... window.onclick = function() {...}
Switz
@Switz : that should be `document.body.onclick`
Aviral Dasgupta
Still not working. I assume it's because once I click on the button, the script runs through and if the script ends then it will no longer recognize the click..
Switz
@Switz : Post your code here.
Aviral Dasgupta
In first post..
Switz
@Switz : Entire webpage. Are you sure that `performEvent` is being called?
Aviral Dasgupta
performCommand and yes. I'd rather not post the full page as to save my code. Regardless everything up to that point works, so there's no reason that I can see why it won't other than disallowing it by Apple.
Switz