1

I was trying to load Addthis JavaScript on click of an html element. This is just my test page. After loading the script, it adds entries to browser history. it happens only in Firefox. Here is the test code

<div class="addthis_toolbox addthis_default_style">
    <a class="addthis_button_tweet"></a><a class="addthis_button_pinterest_pinit"></a>
    <a class="addthis_counter addthis_pill_style"></a>
</div>

<div style="margin:20px;">
  <input id="Button1" type="button" value="Test" onclick="Test();" />
</div>


<script type="text/javascript">
    function Test() {
        var script = 'http://s7.addthis.com/js/300/addthis_widget.js#pubid=xa-5187e240231ec1b0#domready=1';
        $.getScript(script);

    }


</script>

Is it possible to avoid adding entries to browser history?

Kumar
  • 79
  • 2
  • 8

1 Answers1

0

This is caused by AddThis's click tracking, which can be turned off. Make sure you understand what it is first...more info here:

http://support.addthis.com/customer/portal/articles/381252-click-tracking#.UYf404JaXY8

Matt Browne
  • 12,169
  • 4
  • 59
  • 75
  • Even disabling click tracking did not help. Any other solution please. This is very annoying in Firefox. – Kumar May 07 '13 at 13:24
  • Can anyone help? If it is a Firefox or Addthis design problem then ignore it. – Kumar May 07 '13 at 17:21
  • Sorry, I don't know much more about it than that...I wonder if maybe your attempt at disabling click tracking didn't work for some reason? Is it still appending hash values to the end of the URL? If you successfully turned it off there shouldn't be any # (followed by a hash value) at the end of the URL. – Matt Browne May 08 '13 at 16:13
  • I think u did not understand my question. I am not talking about # in url. If u debug the Addthis script, u will find it creates hidden
    in Head element which has Iframe. When script loaded it creates entry in Firefox history which should not happen. I have to click back button 2 times to go back.
    – Kumar May 08 '13 at 17:57
  • Open http://jsfiddle.net/5QmbA/2/ and hit run. In Firefox u will have to click back button 1 times more than any other browser. – Kumar May 08 '13 at 18:13
  • Ah, in that case I'm not sure. Maybe this will help? http://stackoverflow.com/questions/5259154/firefox-back-button-vs-iframes – Matt Browne May 08 '13 at 20:35
  • Since it is the Addthis script which sets iframe source, I cannot control how the source of iframe is being set. Addthis script is third party script and I cannot change its code. – Kumar May 09 '13 at 13:41
  • Good point...I guess then your only option is to detect when the iframe is created and replace it with your own, as recommended here: http://stackoverflow.com/a/8681618/560114. It's been a while since I worked with AddThis, so I don't remember if it lets you pass a callback to run when it's finished setting itself up. If not, then you could use setInterval in conjunction with a function to see when the iframe has been created, then replace it with your own. – Matt Browne May 09 '13 at 20:41
  • It will be too late by the time Addthis script appends the iframe to dom and sets its src property. The problem is Addthis script sets src property multiple times (First empty and then real url). If src property is set only once to the correct one then no issue. I think I have to live with that or I have to override document.append function which I don't want to hack. Anyway thanks Matt. – Kumar May 13 '13 at 13:32
  • There might be one more possibility...if AddThis exposes the function that sets the `src` property then you might be able to override it before you call `addthis.button(...)` (assuming you're calling it manually, which I think you'd have to for this to work), i.e. `addthis.foo = function() { /*overridden foo*/ }`. I see that AddThis has a new events API so you might be able to hook into that to make sure the method gets overridden in time. Might be too much trouble or impossible depending on whether the method you'd need to override is publicly exposed, just thought I'd mention it. – Matt Browne May 13 '13 at 18:30
  • 1
    I logged a bug on Addthis site. They have confirmed the issue and promised to fix it as soon as possible. Until then I will live with that. – Kumar May 17 '13 at 17:02