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. 动态修改css 规则

    页面引用了两个样式表: <link href="css/mui.min.css" rel="stylesheet" /> <link href ...

  2. Zeroc Ice 3.6.1 生成 vs2015 c++ 版本库及相关配置

    背景: 目前发布的Ice最新版本为3.6.0,使用的vs2013编译的,vs2015版本正在开发,发布只是时间问题: 不过官方实在给力,github上的源码已经支持vs2015编译了.源码版本为3.6 ...

  3. Linux操作系统,服务器端的主流

    1.无意之间,一直使用的Windows,其实也是在Unix的基础之上开发的,什么xp,win7等都是,就是Unix的一些堆砌,其实这样说也不对.但是windows的复杂程度比Linux要复杂,因为Wi ...

  4. WinRAR 代码执行漏洞复现

    影响版本: WinRAR < 5.70 Beta 1 Bandizip    < = 6.2.0.0 好压(2345压缩)    < = 5.9.8.10907 360压缩    & ...

  5. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165233

    Exp0 Kali安装 安装过程 1.首先我的Mac上已经安装好了VMware Fusion,所以直接下载对应的虚拟机版本的Kali即可. 2.进入Kali官网进行下载. 以下为下载链接: Kali ...

  6. python入门-异常

    1 报错的例子 print(5/0) 2跳过报错的例子 try: print(5/0) except ZeroDivisionError: print("You can't divide b ...

  7. CUDA C Programming Guide 在线教程学习笔记 Part 4

    ▶ 图形互操作性,OpenGL 与 Direct3D 相关.(没学过,等待填坑) ▶ 版本号与计算能力 ● 计算能力(Compute Capability)表征了硬件规格,CUDA版本号表征了驱动接口 ...

  8. Linux开机挂载windows共享文件夹

    https://blog.csdn.net/zhaogang1993/article/details/79573271  (可行) 命令: mount -t cifs -o username=&quo ...

  9. 网络软工个人作业4——Alpha阶段个人总结

    1.个人总结 (1) 类型 具体技能和面试问题 现在的回答 毕业时找工作 语言 拿手的语言 Java 软件实现 有没有在别人的代码基础上进行改进,你是怎么读懂别人的代码,你采取什么方法不影响原来的功能 ...

  10. leetcode13

    public class Solution { private int ChangeToInt(char c) { ; string s = c.ToString(); switch (s) { ca ...