是否可以手动调用dom对象上的单击? [英] is it possible to manually call a click on a dom object?

查看:102
本文介绍了是否可以手动调用dom对象上的单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用addthis,他们有一堆混淆的代码,我不喜欢在他们的嵌入式JavaScript中挖掘。我想在我的页面上点击他们的一个按钮而无需用户触摸它。

I am using addthis and they have a bunch of obfuscated code that I am loathe to dig through in their embedded javascript. I would like to "click" one of their buttons on my page without the user having to touch it.

所以,实质上,有一个< a> 包含其按钮(当用户点击它时,它们的嵌入式javascript处理)。我想通过我自己的javascript为它们点击它,但是看不到任何类似于与锚标记对象相关联的原生clickMe()函数。

So, in essence, there is a <a> that contains their button (which their embedded javascript handles when the user clicks it). I would like to "click" it for them, via my own javascript, but don't see anything like a native "clickMe()" function associated with the anchor tag object.

是否可以执行此操作,或者由于安全问题,是否缺少规范?

Is it possible to do this, or is it missing from the spec due to security concerns?

推荐答案

所以,事实证明这是一个问题,每个解决方案看起来像锤子,因为我们检查问题假设它是一个指甲。

So, this turns out to be a problem where every solution looks like a hammer, as we examine the problem assuming it's a nail.

执行此操作的方法(并且它是100%跨浏览器)只是将页面重定向到链接的href所设置的任何内容。

The way to do this (and it's 100% cross browser) is simply to redirect the page to whatever addthis has set as the href to the link.

换言之......

self.location.href = document.getElementById("addThisFbLink").href;

这就是它的全部内容。

@kooilnc,我很感激你的解决方案,这不是我需要的,但在某种程度上它让我想出了这个,所以谢谢。

@kooilnc, I appreciate your solution, it wasn't what I needed, but in a way it led me to figuring this out, so thanks.

这篇关于是否可以手动调用dom对象上的单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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