2012-05-14 68 views
1

我想处理WebView中的mouseDown事件。我subclassed WebView,实施了mouseDown,我才知道mouseDown被重定向到WebHTMLView如何在WebView中捕获mouseDown事件?

我已经通过以下链接。

mouseDown: not firing in WebView subclass

从上面的链接我知道了,我们可以在mouseDownEvent重定向到的Objective-C,但我没有找到这方面的任何解决方案。我可以使用任何指针或示例JavaScript来实现相同的功能。

我试过webview子类中的hitTest方法。

- (NSView*)hitTest:(NSPoint)aPoint 

是否可以识别上述方法中的mouseDown?

回答

0

我用下面的HTML和JavaScript捕捉mouseEvents和显示位置点击WebView

<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title></title> 
    <script type="text/javascript"> 
    function SetValues() 
    { 
     var s = 'X=' + window.event.clientX + ' Y=' + window.event.clientY ; 
     document.getElementById('divCoord').innerText = s; 

    } 
</script> 
</head> 
<body id="bodyTag" onclick=SetValues()> 
<div id="divCoord"></div> 
</body> 
</html> 
1

可以使用onTouchStart事件为同一.Refer这link to bind events on iphone

或使用: -

$('button').bind("touchstart", function(){alert('hey'}); 

touchstart相当于鼠标按下

另一个解决方案是元素的设置光标指针,它使用jQuery live和click事件。在CSS中设置它(光标:指针)

在您可以使用的javaScript中: -

node.ontouchmove = function(e){ 
    if(e.touches.length == 1){ // Only deal with one finger 
    var touch = e.touches[0]; // Get the information for finger #1 
    var node = touch.target; // Find the node the drag started from 
    node.style.position = "absolute"; 
    node.style.left = touch.pageX + "px"; 
    node.style.top = touch.pageY + "px"; 
    } 
} 

document.addEventListener('touchstart', function(event) { 
    alert(event.touches.length); 
}, false); 

更多细节请参考javascript iPhone Events

对于Mac OSX见The Link

+0

corona zorro:这不是iPhone.Do you have any tips for same same Cocoa? – Ram

+0

Cocoa Touch是一个用于构建软件程序的UI框架,可以从Apple Inc.在iPhone,iPod Touch和iPad上运行。因此,它也可以用于这些应用程序,它只是iPhone的一部分。 –

+1

他要求mac os x。 – vikingosegundo