如何使用 JavaScript 中的 x,y 坐标模拟点击? [英] How to simulate a click by using x,y coordinates in JavaScript?

查看:31
本文介绍了如何使用 JavaScript 中的 x,y 坐标模拟点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用给定的坐标来模拟网页中 JavaScript 中的点击?

Is it possible to use given coordinates in order to simulate a click in JavaScript within a webpage?

推荐答案

您可以调度 click 事件,尽管这与真正的点击不同.例如,它不能用于诱使跨域 iframe 文档认为它已被点击.

You can dispatch a click event, though this is not the same as a real click. For instance, it can't be used to trick a cross-domain iframe document into thinking it was clicked.

所有现代浏览器都支持 document.elementFromPointHTMLElement.prototype.click(),因为至少 IE 6、Firefox 5、任何版本的 Chrome 和可能的任何版本您可能会关心的 Safari 浏览器.它甚至会跟踪链接并提交表单:

All modern browsers support document.elementFromPoint and HTMLElement.prototype.click(), since at least IE 6, Firefox 5, any version of Chrome and probably any version of Safari you're likely to care about. It will even follow links and submit forms:

document.elementFromPoint(x, y).click();

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆