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. android自定义tabhost,tabcontent用intent获得

    地址:http://my.oschina.net/aowu/blog/36282 自己改的自定义tabhost组建,效果图如左.有更好的朋友可以相互交流一下,嘿嘿. 1.先上AndroidManife ...

  2. apache-cxf-2.6.3 spring集成配置

    apache-cxf-2.6.3 <?xml version="1.0" encoding="UTF-8"?><beans xmlns=&qu ...

  3. 安装Linux软件时没有图形界面的问题

    Q: 现在Linux下的软件有很多也采用图形界面安装了:但有时候我们发现启动安装程序时本该出现图形界面时却出现了文本界面. A: 检查常用的图形函数库(最主要的自然是gtk, qt)是否已安装.尤其是 ...

  4. [模板] KMP字符串匹配标准代码

    之前借鉴了某个模板的代码.我个人认为这份代码写得很好.值得一背. #include<bits/stdc++.h> using namespace std; const int N=1000 ...

  5. java study2

    Intellj小技巧 数组 1.java数组元素类型是唯一的,即一个数组只能存储一种数据类型的数据,而不能存储多种数据类型的数据. 2.java数组的长度,一旦初始化完成,控件就被固定,即数组的长度将 ...

  6. 关于Linux DNS部分处理

    如果不能ping 通外网地址进行解析的话进行如下处理

  7. 关于ESXI5.0版本+ Broadcom BCM5720的BUG

    主要发生在网卡 Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet 和ESX 5.0之前的版本. 虚拟机的网络突然不通,必须删除网卡重新创建 ...

  8. numpy的where函数

    numpy.where(condition[,x,y]) condition是条件,x,y是可选参数,这三个输入参数都是array_like的形式且三者的维度相同 当conditon的某个位置为tru ...

  9. centos 7 mount usb hard disk(ntfs format)

    1. yum install -y epel-release* 2. yum install -y ntfs-3g 3. 命令:fdisk -l (查看磁盘分区信息) [root@devserverg ...

  10. Flex工程师面试

    这几天有一家公司需要招聘Flex开发的工程师,要求开发电力行业的WebGIS的电力方面的程序,当时也是被推荐过去的,随后的几天,自己也准备的一下,因为之前接触Flex的主要是开发一些医疗的项目,利用F ...