Google Docs - Programmatically Send Mouse Click To An Item In Outline Pane
In Google Docs you can open outline pane and see all headers in the document, you can also click on an header and the view will scroll to header. My question is how simulate mouse
Solution 1:
From this answer:
Try with this code; it simulates a mouse left click on the element by a quick succession of mousedown, mouseup and click events fired in the center of the element:
var simulateMouseEvent = function(element, eventName, coordX, coordY) {
element.dispatchEvent(new MouseEvent(eventName, {
view: window,
bubbles: true,
cancelable: true,
clientX: coordX,
clientY: coordY,
button: 0
}));
};
var elementToClick = document.querySelector('#mytest1');
var box = elementToClick.getBoundingClientRect(),
coordX = box.left + (box.right - box.left) / 2,
coordY = box.top + (box.bottom - box.top) / 2;
simulateMouseEvent (elementToClick, "mousedown", coordX, coordY);
simulateMouseEvent (elementToClick, "mouseup", coordX, coordY);
simulateMouseEvent (elementToClick, "click", coordX, coordY);
Post a Comment for "Google Docs - Programmatically Send Mouse Click To An Item In Outline Pane"