开发者

How do I recognize a mouseclick in a webpage from a Safari extension?

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.

开发者_Go百科    function performCommand(event)
{
    /*removed*/
//It reaches this point
        document.body.onclick = function() { 
        //Never reaches this point
/*removed*/
    }
}


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜