May 3, 2013

f Comment

Fixing the ShareThis Widget Installation Error in SECONDS!

AmazonShareThis is one of the most popular widgets that you can use to make your website social. However if you are trying to install the ShareThis widget on your site you may get the following error when testing on your local web server:

"Uncaught TypeError: Cannot read property 'length' of undefined" produced by http://s.sharethis.com/loader.js
If you expand the errors in Chrome's web developer toolbar console you may see the following trace.

jquery.min.js:166
Uncaught TypeError: Cannot read property 'clientHeight' of null
c.fn.(anonymous function)
...

loader.js:1
Uncaught TypeError: Cannot read property 'length' of undefined
_stdHash
_stFpc
initialize
sharethis.globals
(anonymous function)


If you use Firefox you may see the following error.

TypeError: f.document.body is null jquery.min.js (line 166)
Read on to see how to solve this issue.

The Root Cause
The problem is http://s.sharethis.com/loader.js is trying to split the domain name by dots before invoking the length property on the result. So if the domain you are testing the ShareThis widget on is http://localhost then you will get this JavaScript error.

If you get the "Cannot read property 'length' of undefined" error or "TypeError: f.document.body is null" error caused by jquery.min.js it's possibly due to the fact your DOM is not ready before jquery tries to manipulate it.

In this case simply move JavaScript inclusion line to the ending body tag like the following:

...
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</body>
</html>

Solution
Knowing the root cause you can simply use a domain with at least one dot within it. For example try http://127.0.0.1 and hopefully you'll see the ShareThis widget showing up!

Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael