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

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

问题描述

是否有可能使用给定的坐标来模拟网页中的JavaScript点击? 您可以调度一个点击事件,尽管这与真正的点击不同。例如,它不能用来欺骗跨域iframe文档,以为它被点击。



所有现代浏览器都支持文档。 elementFromPoint HTMLElement.prototype.click(),因为至少IE 6,Firefox 5,任何版本的Chrome以及可能的任何版本的Safari '很可能关心。它甚至会跟随链接和提交表单:

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

https://developer.mozilla.org/En/DOM:document.elementFromPoint
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click


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

解决方案

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.

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();

https://developer.mozilla.org/En/DOM:document.elementFromPoint https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click

这篇关于如何在JavaScript中使用x,y坐标来模拟点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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