Is it possible to programmatically (using stringByExecutingJavascript most likely) set the mouse position (x,y) "perceived" by HTML-5 elements on a UIWebView so that it would trigger hover, mouse over, etc...
            Asked
            
        
        
            Active
            
        
            Viewed 233 times
        
    0
            
            
         
    
    
        BadPirate
        
- 25,802
- 10
- 92
- 123
1 Answers
1
            I don't think this can be done using public api. But you can do that using JavaScript like here: How to simulate a mouse click using JavaScript?:
function simulate(element, eventName)
{
    var options = extend(defaultOptions, arguments[2] || {});
    var oEvent, eventType = null;
    for (var name in eventMatchers)
    {
        if (eventMatchers[name].test(eventName)) { eventType = name; break; }
    }
    if (!eventType)
        throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
    if (document.createEvent)
    {
        oEvent = document.createEvent(eventType);
        if (eventType == 'HTMLEvents')
        {
            oEvent.initEvent(eventName, options.bubbles, options.cancelable);
        }
        else
        {
            oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
      options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
      options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
        }
        element.dispatchEvent(oEvent);
    }
    else
    {
        options.clientX = options.pointerX;
        options.clientY = options.pointerY;
        var evt = document.createEventObject();
        oEvent = extend(evt, options);
        element.fireEvent('on' + eventName, oEvent);
    }
    return element;
}
function extend(destination, source) {
    for (var property in source)
      destination[property] = source[property];
    return destination;
}
var eventMatchers = {
'HTMLEvents':     /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|s    croll)$/,
    'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
}
var defaultOptions = {
    pointerX: 0,
    pointerY: 0,
    button: 0,
    ctrlKey: false,
    altKey: false,
    shiftKey: false,
    metaKey: false,
    bubbles: true,
    cancelable: true
}
 
    
    
        Community
        
- 1
- 1
 
    
    
        Nikita Zernov
        
- 5,465
- 6
- 39
- 70