我在 iframe 中打开一个站点,有一个div我想在其中单击其 ID 的元素#thearea。
当我“定位”#thearea时,我设置的坐标是相对于#thearea,还是相对于整个窗口/文档?
因此,下面的示例基本上具有10,10x/y 坐标,即10/10从窗口的角落或目标被调用10/10的角落。div#thearea
v = frames[1];
target = v.document.getElementById('thearea');
var oEvent = document.createEvent('MouseEvents');
oEvent.initMouseEvent(
'click' // event type
,true // can bubble?
,true // cancelable?
,window // the event's abstract view (should always be window)
,0 // mouse click count (or event "detail")
,0 // event's screen x coordinate
,0 // event's screen y coordinate
,10 // event's client x coordinate
,10 // event's client y coordinate
,false // whether or not CTRL was pressed during event
,false // whether or not ALT was pressed during event
,false // whether or not SHIFT was pressed during event
,false // whether or not the meta key was pressed during event
,1 // indicates which button (if any) caused the mouse event (1 = primary button)
,null // relatedTarget (only applicable for mouseover/mouseout events)
);
target.dispatchEvent( oEvent );