Quick JavaScript hack/fixing of a jQuery problem

My site is a WP site. I use the popular Accordion Shortcodes plugin to handle my product's pages. Also I use the even more popular Share Buttons by AddThis plugin to allow social sharing. But they don't want to work together. This was a several months journey, to test, think and find the problem. And the result was a surprise: none of them was the problem.

The Accordion plugin uses jQuery to handle shrinkable tabs. The Sharing plugin uses codes like "#.Vklev3q350w" in the URL to track clicks. But somehow jQuery can't parse these URLs well (I am not checked why), and generates errors. Sorry, can not say which error exactly, but the result was, that accordion tabs was locked.

I try to switch down the tracking code. I not need to track clicks with this plugin, I use another plugin which gives me better understanding of the info. But no way to disable the code, plugin don't allows. Even the account at AddThis site don't allows.

I try to remove some of the plugins, but I need them both.

I try to replace some of them, but replacements was not good enough for me, so I really have to use these two.

I try to remove the "infarct" part of the URL by a mu-plugin script, and to do silent "wp_redirect". But browsers don't send the hash part of the URL back to the server, so script can not see it at all.

OK, what if I remove the hash before the jQuery initialization? To run before the jQuery, must not wait for page to finish the loading process. And not need, as it don't works with objects on the page.

So I put at top of my header (just before the "title" tag) this JavaScript code:

var kcre = /#/;
if(window.location.toString().search(kcre) != -1) {
  kcurl = window.location.toString().split('#');
  window.location = kcurl[0];

As you can see, this procedure checks for "the hash key", then cuts out the hash from the URL. It is not perfect, as URL location is defined as:


Means, it should cut out entire QUERY_STRING with parameters. Fortunately I am never seen URLs with both hash and parameters, hope my site don't have such ones. So this should work for me. Or I will have to edit this article :-) Not a problem to check for questionmark char and to glue two parts I need.

Hope I can help you to short your research and fixing time with similar problems. Sorry, not much details.

Share this

This entry was posted in Blog, Hacks and tagged , , , , . Bookmark the permalink.

Leave a Reply