Topic: [FF+FireBug] Location is null

Hi all,

I am currently using Xajax in a new project. I just started the project and
it is not available in the net atm - so I cannot provide a working example.

However, I found the following very strange bug / behaviour:

All XAJAX functionality just runs fine. However, when I open a new tab in
FireFox - the following JavaScript error appears in FireBug:

Location is null

This points to the following line

try { if (undefined == xajax.config) xaj... (e) { xajax = {}; xajax.config = {}; };

Although this error mesasge appears - my program still seems to run stable.

When I disable FireBug I do not get any script error in FireFox own
scripting debugger?

Does anyone know if this is a problem of FireBug+XAJAX or is it a problem
in my code ?

My development environment is:
Xajax 0.5RC2, Firefox3.0, FireBug V1.2.1, Windows Vista

Thanks in advance,

Re: [FF+FireBug] Location is null

Hi benny! I'm using Firefox 3.0.5, Firebug 1.2.1 on Ubuntu 8.04 and although I've never got the 'Location is null' error I have experienced a similar effect when I've selected the 'Break on all errors' option in Firebug and find that Firebug will halt at the 'try { if (undefined == xajax.config) ...' line.

You could if you're curious try prefixing the xajax javascript with the 'if (typeof xajax == "undefined")' construct one often sees in javascript libraries (seems to be the bullet-proof method) which gets rid of the problem for me, eg.

<?php echo str_replace('try { if (undefined == xajax.config)', 'if (typeof xajax == "undefined") xajax = {}; try { if (undefined == xajax.config)', $xajax->getJavascript()); ?>

It is a bit of a pet peeve of mine that javascript developers (however wonderful) tend to use what I would consider totally unnecessary (because totally predictable) try catch blocks.

Re: [FF+FireBug] Location is null

Thanks a lot for that hint. I will try it over the xmas days. I will
report if it helped or not. Thanks!

Re: [FF+FireBug] Location is null


I didnt worked on the project over christmas / New year - just now I
found the time to try out your workaround.

I did what you suggested and played around with the page, open tabs
in Firefox and closes them again ... and the error seems to be disap-
peared (finger crossed that it stays away ;-) ).

So, thanks a lot for this tip. Maybe the javascript code in the official
xajax release should be replaced by it - shouldnt do it any harm - should


Re: [FF+FireBug] Location is null

Good to hear, benny! I agree with you, it'd be nice if it was in the official release and I can't see it doing any harm. Anyway after you brought it up I overrode getJavascript() to do the above (I superclass xajax for convenience, similar to the way one uses Smarty) like so (PHP5):

/** Override to prepend check for xajax. Avoids unnecessary exception. */
function getJavascript($sJsURI='', $aJsFiles=array()) {
    $ret_val = parent::getJavascript($sJsURI, $aJsFiles);
    $ret_val = str_replace('try { if (undefined == xajax.config) xajax.config = {}; } catch (e)',
                                'if (typeof xajax == "undefined" || typeof xajax.config == "undefined")', $ret_val);
    return $ret_val;

Re: [FF+FireBug] Location is null

Sounds good, dickdock. Looking good.

Re: [FF+FireBug] Location is null

Ahh ... just remember. I think there is also a method called printJavascript which
directly prints the javascript out. To be consistent because maybe others use printJavascript
instead of getJavaScript those should override this method, too.

Re: [FF+FireBug] Location is null

Yeah benny! and it's messy and a bit OTT to override printJavascript() so I guess those who output directly will have to live with the consequences of their folly...