Search code examples
javascripteventsaddthis

is it possible to manually call a click on a dom object?


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.

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?


Solution

  • 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.

    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.

    In otherwords...

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

    That's all there is to it.

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