0

I have tried all the solutions listed in the following link: jQuery/HTML - Disable OnClick but none of them work for me.

I am trying to stop an onclick event from an external .js from firing. The .js is here http://x.instagramfollowbutton.com/follow.js - it can be unminified at http://unminify.com/

The script is included on my site with the following:

(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src="//x.instagramfollowbutton.com/follow.js";s.parentNode.insertBefore(g,s);}(document,"script")); 

The resulting HTML code is:

<span class="ig-follow" data-id="*deleted*" data-handle="*deleted*" data-count="true" data-size="small" data-username="false"><div title="Follow @*deleted* on Instagram" class="IGF small"><div class="ig-background"><img class="ig-camera" src="//x.instagramfollowbutton.com/components/instagram/v2/img/ig-camera.png" height="16" width="16"><span class="ig-text">Follow</span></div><div class="ig-count" id="c"><i></i><u></u><a>217</a></div></div></span>

How can I stop the external script's onclick event from firing?

Again, I have tried all the solutions listed in the following link: jQuery/HTML - Disable OnClick but none of them work for me.

9
  • 1
    If the element is in an iframe of a different domain, you can not touch that click event. Commented Feb 22, 2016 at 17:30
  • Nope its not in an iframe, its within my domain Commented Feb 22, 2016 at 17:30
  • You sure it doesn't wrap it inside iframe??? Commented Feb 22, 2016 at 17:31
  • 1
    .ig-follow { pointer-events: none; } would be enough then on modern browser, otherwise check which element is bound click handler and remove it. But that's not clear exactly why you are trying to do. Bind your own event or just remove all click ones making button useless? A simple example replicating your issue would certainly help Commented Feb 22, 2016 at 17:34
  • 2
    But keep in mind caniuse Support on IE is really bad Commented Feb 22, 2016 at 17:36

1 Answer 1

0

Instagram seems to be very greedy with its click handlers. Try using .stopImmediatePropagation() instead. Note that IE support is 9+ for this.

Broken: https://jsfiddle.net/jmarikle/4Loukhm6/
Fixed: https://jsfiddle.net/jmarikle/4Loukhm6/1/

Never heard of .stopImmediatePropagation() before this, but this article seems to have a nice explination of it: https://codeplanet.io/preventdefault-vs-stoppropagation-vs-stopimmediatepropagation/

(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src="//x.instagramfollowbutton.com/follow.js";s.parentNode.insertBefore(g,s);}(document,"script"));

document.querySelector('.ig-follow').addEventListener('click', function(event){
  event.stopImmediatePropagation();
});
<span class="ig-follow" data-id="*deleted*" data-handle="*deleted*" data-count="true" data-size="small" data-username="false"><div title="Follow @*deleted* on Instagram" class="IGF small"><div class="ig-background"><img class="ig-camera" src="//x.instagramfollowbutton.com/components/instagram/v2/img/ig-camera.png" height="16" width="16"><span class="ig-text">Follow</span></div><div class="ig-count" id="c"><i></i><u></u><a>217</a></div></div></span>

Sign up to request clarification or add additional context in comments.

4 Comments

@DavidZ What browser are you using? Even stripping the demo of the jsfiddle junk still works for me: output.jsbin.com/ragizehumu
Google Chrome, I'm running all the jQuery commands in the console and laughing when they all fail, start a discussion with me and I'll show you a live link?
@DavidZ Sure. Just head over to chat.stackoverflow.com and I can invite you or you can invite me. Edit: Actually I'll have to invite you. I think that's a privilege setting.
@JosehMarikle okay I'm there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.