"Cannot read property 'offsetWidth' of null" Error

Permalink 2 users found helpful
On this page:http://www.fagenpharmacy.com/stores/indiana/demotte/...

I'm getting an error that reads "Cannot read property 'offsetWidth' of null". I know the error is being caused by a piece of javascript in the footer of the page dealing with Google maps. But, as you can see on the page, there is no Google map (ignore the popup window map - it has nothing to do with this problem).

At one time, I'm sure that this page had a Google map block on the page, but that was removed in favor of a pop-up map, for whatever reason. The problem is that this piece of code is persisting at the bottom of the page. I've tried clearing the cache, I refreshed the block, I tried different themes and designs and still the code persists.

Any ideas????

rbarcus
View Replies:
mkly replied on at Permalink Reply
mkly
My guess is that it's either in the theme or in your Tracking Codes section. Type "Tracking Codes" into the intelligent search box.
rbarcus replied on at Permalink Reply
rbarcus
Nope, not in the tracking code or in the theme. I have looked and high and low for the problem and I still can't find it. I did look up the coordinates listed in the javascript code, and it definitely matches the location of the store found on the page (but again, no map is on the page)... this is the only page where this error is showing up.
adajad replied on at Permalink Reply
adajad
I have found that the problem with offsetWidth of Null (or 'a is null') comes from not having a set width on the parent div. And since your javascript code is trying to locate the element with id="googleMapCanvas494", and can't find it, the error is thrown.

function googleMapInit494() { 
      try{
      var latlng = new google.maps.LatLng(41.205055, -87.1977);
      var mapOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      streetViewControl: false,
      mapTypeControl: false
      };
   var map = new google.maps.Map(document.getElementById('googleMapCanvas494'), mapOptions);
   var marker = new google.maps.Marker({
         position: latlng, 
      map: map
      });


Have you previously had a map on that page (your popitup() function shouldn't interfere since you are calling a different page holding an iframe)? Could it have been hard coded in your page type (or added as a default in the page type)? When in edit mode, do you have any 'empty' blocks somewhere (that when edited holds the javascript code)?
JohntheFish replied on at Permalink Reply
JohntheFish
The generic maps problem is addressed by:
http://www.concrete5.org/documentation/how-tos/developers/improve-r...

Though I don't think that is the solution here.
rbarcus replied on at Permalink Reply
rbarcus
To answer a few of your questions, I'm almost positive that there was a Google map on the page at one time, but there is not one now. I agree with you that the popup isn't the problem.

The page type also doesn't contain any such code and the page type is used on 20+ other pages without any issues. There are no hidden or empty blocks on the page while in edit mode.

However, your comments did lead me to come up with a quick and easy solution, even if doesn't exactly 'fix' the problem. I just added an HTML block with the simple code:

<div id="googleMapCanvas494"></div>


It doesn't affect the page in any way, except it gives the rogue javsascript code something to work with. It gets rid of the annoying alert message, which is what is most important to me.

Still, it would be nice to find a real solution.
foster replied on at Permalink Reply
foster
I had a problem where old Lorem Ipsum content was showing in search results long after it had been deleted from the page... reference link:http://www.concrete5.org/community/forums/customizing_c5/search-res...

Basically, I ended up searching through the database file to find the content that was still hanging around. After deleting it and restoring from backup - everything was fixed.

I'd recommend making a local copy of your site and trying this fix locally before doing anything on the live site, though. Just to be on the safe side.
Deladroid replied on at Permalink Reply
Deladroid
In the case someone else runs into this, I have an explanation.

I had an editor block, such as:
<?php 
         $a = new Area('footer widget2 map');
         $a->display($c);
         ?>


I added a Google Map block to this, set it up, approved it, but then decided I was going to do something different with the editor blocks and removed "footer widget2 map" in favor of "footer widget2" (to encompass widget title and content).

I then ran across the error the OP described.

Luckily, I remembered what I named the editor block and just added it back temporarily, deleted the Google Map content block I had (it showed back up), and then went back and removed the editor block.

All was good in the world.
webicine replied on at Permalink Reply
webicine
Thanks for this message - this was the solution to an issue I was having as well.