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. 多线程执行顺序诡异现象谈,你不知道的pthread_create

    引文:学而时习之,不亦说乎.总是忙于具体项目,业务功能的实现:关于编程本身的技能都要有些生疏了,于是就选择了几个专题做了一次温习,重点放在了多线程和多进程上,跑了一个实例,居然有新的发现: (1)多个 ...

  2. [转]SendKeys.Send 方法

    SendKeys.Send 方法 向活动应用程序发送击键. 转载自: https://msdn.microsoft.com/zh-cn/library/system.windows.forms.sen ...

  3. 接口测试3-2csv格式

    csv文件数据 IntellJ IDEA打开终端:view-tool windows-terminal,可以在终端中查看文件路径 阿里 马云 京东 刘强东 京东 马化腾 #java //读取csv文件 ...

  4. [UE4]ue4 c++学习推荐

    我由易到难推荐,不过在此之前还是先看看官方对于VS设置的推荐: https://docs.unrealengine.com/latest/INT/Programming/Development/Vis ...

  5. git如何查看某个人提交的日志。

    我们知道,在git进行cherry-pick的时候,找到commit id是至关重要, 如果我们是很多人在一个分支开发,开发完了之后,发现某个人的功能,需要单独cherry-pick到另外一分支上去. ...

  6. Open Live writer 远程博客管理客户端

    1.  官网地址:http://openlivewriter.org/ 点击download下载:https://openlivewriter.azureedge.net/stable/Release ...

  7. Vue基础知识之组件及组件之间的数据传递(五)

    vue中的组件是自定的标签,可以扩展的原生html元素,封装可复用的代码 note: 1.在标签命中不要使用大写,标签名字必须用短横线隔开 2.模板中只能有一个根元素,不能使用并列标签. 定义组件 全 ...

  8. 序列化 ,hashlib ,configparser ,logging ,collections模块

    # 实例化 归一化 初始化 序列化 # 列表 元组 字符串# 字符串# .......得到一个字符串的结果 过程就叫序列化# 字典 / 列表 / 数字 /对象 -序列化->字符串# 为什么要序列 ...

  9. [Python] 牛顿插值

    插值公式为: 差商递归公式为: # -*- coding: utf-8 -*- #Program 0.4 Newton Interpolation import numpy as np import ...

  10. 知乎日报 API的图片盗链问题

    由最近 基于vue的知乎日报单页应用 引发的问题 以及问题解决历程 通过 知乎日报API 基于vue做一个知乎日报的单页应用,在获取图片时存在一个图片盗链问题,图片无法加载 提示 403 错误, 最终 ...