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. Asp.Net中使用Newtonsoft.Json转换,读取,写入

    using Newtonsoft.Json;using Newtonsoft.Json.Converters; //把Json字符串反序列化为对象目标对象 = JsonConvert.Deserial ...

  2. [转] with (nolock) 解释

    本文来自:http://blog.sina.com.cn/s/blog_5fafba5e010113kr.html select * from t1 WITH(NOLOCK) select * fro ...

  3. ActiveMQ 高可用集群安装、配置(ZooKeeper + LevelDB)

    ActiveMQ 高可用集群安装.配置(ZooKeeper + LevelDB) 1.ActiveMQ 集群部署规划: 环境: JDK7 版本:ActiveMQ 5.11.1 ZooKeeper 集群 ...

  4. API网关Kong系列(一)初识

    最近工作需要,加上国内Kong的文章相对缺乏(搜来搜去就那么两篇文章),而且官方文档在某些demo上也有一些过时的地方,遂提笔记录下这些,希望能有帮助. 先随大流介绍下KONG(主要参考官网): 官方 ...

  5. 第3章 文件I/O(4)_dup、dup2、fcntl和ioctl函数

    5. 其它I/O系统调用 (1)dup和dup2函数 头文件 #include<unistd.h> 函数 int dup(int oldfd); int dup2(int oldfd, i ...

  6. 第2课 C 到 C++ 的升级

    1.  C与C++的关系 (1)C++继承了所有的C特性,并在C的基础上提供了更多的语法和特性. (2)C++的设计目标是运行效率与开发效率的统一,它更强调的是语言的实用性. 2. C到C++ 的升级 ...

  7. JQ树插件 — zTree笔记

    1.zTree作者很贴心的为使用者将不同功能的代码封装成不同的文件,方便大家尽量减少加载的代码量,如果基本全用到,则不必一个个引用,有一个文件“jquery.ztree.all.js”,包含了所有.如 ...

  8. leetcode258

    public class Solution { public int AddDigits(int num) { var str = num.ToString(); ; foreach (var c i ...

  9. Astah professional 7.2

    分享Astah professional 7.2下载和破解: 官方下载地址:http://astah.net/download 1.免费的community版本 链接:http://pan.baidu ...

  10. 怎样在本地windows安装和配置zookeeper

    Zookeeper是什么?有什么用? Zookeeper是一个分布式协调服务. 作用:为用户的分布式应用程序提供协调服务.  zookeeper在底层其实只提供了两个功能: 1.管理(存储,读取)用户 ...