1

I would like to handle the mouseDown events in the WebView. I subclassed the WebView,implemented the mouseDown and I came to know the mouseDown was redirected to WebHTMLView.

I have gone through the following link.

mouseDown: not firing in WebView subclass

From the above link I got to know, We can redirect the mouseDownEvent to Objective-C,but I did not find any solution for this. Can I have any Pointers or sample javascript to implement the same.

I tried the hitTest method in webview subclass.

- (NSView*)hitTest:(NSPoint)aPoint

Is it possible to recognize the mouseDown in the above method?

Community
  • 1
  • 1
Ram
  • 1,872
  • 5
  • 31
  • 54

2 Answers2

1

You can use onTouchStart Event for the same .Refer this link to bind events on iphone

or use this :-

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

touchstart is equivalent to mouseDown

Another Solution is to set the element's cursor to pointer and it work with jQuery live and click event .Set it in CSS.(cursor:pointer)

IN javaScript you can use :-

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";
  }
}

or

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

for more details refer javascript iPhone Events

For Mac OSx See The Link

Community
  • 1
  • 1
Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25
  • corona zorro :It's not iPhone.Do you have any tips for the same Cocoa ? – Ram May 14 '12 at 09:28
  • Cocoa Touch is a UI framework for building software programs to run on the iPhone, iPod Touch, and iPad from Apple Inc.So,it would work on these also , its just a part of iPhone. – Abhishek Singh May 14 '12 at 09:35
0

I used the following HTML and JavaScript to capture the mouseEvents and to display the position of the mouse click in the 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>
Ram
  • 1,872
  • 5
  • 31
  • 54