try {
  var selector1 = "._3-8y:first-child";
  var evt = document.createEvent("MouseEvents");
  var selector = document.querySelectorAll("._3-8y:first-child")[0];
  console.log(selector)
  var center_x = 2,
  center_y = 2;
  var type = 'mouseover';
try {
  var pos = selector.getBoundingClientRect();
  center_x = Math.floor((pos.left + pos.right) / 2);
  center_y = Math.floor((pos.top + pos.bottom) / 2);
  console.log("center_x", center_x);
  console.log("center_y", center_y);
} catch (e) {}
  evt.initMouseEvent('mouseover', true, true, window, 1, 1, 1, 1326, 157, false, false, false, false, 0, selector);
  // dispatchEvent return value is false if at least one of the event
  // handlers which handled this event called preventDefault;  
  // so we cannot returns this results as it cannot accurately informs on the status
  // of the operation
  // let's assume the event has been sent ok it didn't raise any error
  selector.dispatchEvent(evt);

  

//second
  var selector1 = "._3-8y:first-child";
  var evt = document.createEvent("MouseEvents");
  var selector = document.querySelectorAll("._3-8y:first-child")[0];
  console.log(selector)
  var center_x = 2,
  center_y = 2;
  var type = 'mouseover';
try {
  var pos = selector.getBoundingClientRect();
  center_x = Math.floor((pos.left + pos.right) / 2);
  center_y = Math.floor((pos.top + pos.bottom) / 2);
  console.log("center_x", center_x);
  console.log("center_y", center_y);
} catch (e) {}
  evt.initMouseEvent('mouseout', true, true, window, 1, 1, 1, 1326, 155, false, false, false, false, 0, selector);
  // dispatchEvent return value is false if at least one of the event
  // handlers which handled this event called preventDefault;
  // so we cannot returns this results as it cannot accurately informs on the status
  // of the operation
  // let's assume the event has been sent ok it didn't raise any error
  selector.dispatchEvent(evt);
  //second
  // return true;
} catch (e) {
  console.log("Failed dispatching " + type + "mouse event on " + selector + ": " + e, "error");
  // return false;
}
//
相关链接:
https://stackoverflow.com/questions/28672152/pass-an-event-to-an-iframe-from-the-parent-window-javascript
 
var iframe = document.getElementById('something');
var iframeEvent = new Event('iframe-keypress'); document.addEventListener('keypress', function (e) {
iframe.dispatchEvent(iframeEvent);
}); iframe.addEventListener('iframe-keypress', function (e) {
console.log(e);
});
https://www.3till7.net/2014/08/09/triggering-events-in-an-iframe/index.html
// parent page's JavaScript
var iframe = $('iframe');
var iframe_select = iframe.contents().find('select#menu');
iframe_select.val(value);
var ev = iframe[0].contentWindow.document.createEvent('UIEvents');
ev.initUIEvent('change', true, true, window, 1);
iframe_select[0].dispatchEvent(ev);

 

java script 模拟鼠标事件的更多相关文章

  1. Java&Selenium 模拟鼠标方法封装

    Java&Selenium 模拟鼠标方法封装 package util; import org.openqa.selenium.By; import org.openqa.selenium.W ...

  2. OSG模拟鼠标事件影响操纵器

    viewer->getEventQueue()->mouseButtonPress(0,0,1); viewer->getEventQueue()->mouseMotion(1 ...

  3. js 模拟鼠标事件

    <!DOCTYPE html> <html> <head lang="zh-CN"> <meta charset="UTF-8& ...

  4. Python moni模拟鼠标事件

    7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 4 ...

  5. javaScript事件机制深入学习(事件冒泡,事件捕获,事件绑定方式,移除事件方式,阻止浏览器默认行为,事件委托,模拟浏览器事件,自定义事件)

    前言 JavaScript与HTML之间的交互是通过事件实现的.事件,就是文档或浏览器窗口中发生的一些特定的交互瞬间.可以使用侦听器(或处理程序)来预订事件,以便事件发生时执行相应的代码.这种在传统软 ...

  6. jQuery-3.事件篇---鼠标事件

    jQuery鼠标事件之click与dbclick事件 用交互操作中,最简单直接的操作就是点击操作.jQuery提供了两个方法一个是click方法用于监听用户单击操作,另一个方法是dbclick方法用于 ...

  7. 小试牛刀JavaScript鼠标事件

    鼠标事件练习1 当鼠标点击网页某个单元格的时候,其他的单元格颜色不变,只有被点击的单元格颜色发生变化 <style type="text/css"> *{ margin ...

  8. lufylegend:文本、鼠标事件、键盘事件

    1.文本 <script type="text/javascript">init(50,"mylegend",500,350,main);funct ...

  9. selenium模拟鼠标操作

    Selenium提供了一个类ActionChains来处理模拟鼠标事件,如单击.双击.拖动等. 基本语法: class ActionChains(object): """ ...

随机推荐

  1. sql存储过程输出

    1.存储过程写法 create procedure [dbo].[Y_GetICBillNo] @IsSave smallint, @FBillType int, @BillID VARCHAR (5 ...

  2. jquery select radio

    Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...});   //为S ...

  3. bootstrap+font-awesome表单

    bootstrap+font-awesome表单 <form action="" class="form-horizontal col-sm-offset-4&qu ...

  4. android 自定义radiogroup的两种方式

    这里先备注下 listview+radiobutton实现  浅显易懂 http://www.haolizi.net/example/view_3312.html 在radiogoup原生态源码的基础 ...

  5. 安全测试chicklist

  6. shell 13文件包含

    同其他语言一样,shell也可以包含外部脚本.执行引用脚本可以使用source或 . 示例1 test.sh #shell #!/bin/sh echo "test.sh开始执行" ...

  7. js判断是android访问还是ios访问

    原文地址:http://blog.csdn.net/wy978651775/article/details/9014039 该博主也是转载的,但是没有标明出处. 判断原理: JavaScript是前端 ...

  8. 被折腾的sql编程

  9. 浅析Spring框架之一(Spring简介)

    免责声明 本文为鄙人搜集网络资源并结合自己所思所得整理而成,如有侵权,敬请谅解. 何为spring框架 Spring是一个开源的轻量级控制反转(IoC)和面向切面(AOP)的容器框架. ◆目的:解决企 ...

  10. python 9*9示例

    # 9*9 乘法表# def nine_nine():#     for i in range(1, 10):#         for j in range(1, i+1):#            ...