2012-05-14 37 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