Follow this Blog!

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
If you expand the errors in Chrome's web developer toolbar console you may see the following trace.

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

Uncaught TypeError: Cannot read property 'length' of undefined
(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 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="//"></script>

Knowing the root cause you can simply use a domain with at least one dot within it. For example try 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
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael