Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I identify if I have a javascript conflict on my website?

I'm currently moving a website from self hosted onto a CMS system. The current site uses a modal popup script called SqueezeBox.js I've copied the code across exactly how it looks on the current website, however the modal popup box isn't triggering when I click on a thumbnail image.

Looking at the code in the header I've spotted that the CMS I'm using is also calling a number of other javascript files and I'm wondering if one of them is causing a conflict.

What's the best way to find out if this is the case? I've tried Firefox's plugin Web Developer but can't see anything in the Error Console. However I'm not 100% sure I'm using it correctly. Can anyone else point me in the direction of a simple to use javascript conflict detector?

Cheers

Adam

like image 831
bbacarat Avatar asked Aug 30 '11 17:08

bbacarat


People also ask

How do I find JavaScript conflicts?

A more simple way of checking where problems are occuring is by adding an alert('im working); or something similar to code you're not sure if it's working. You can also alert a variable to see what the value is at that point. You can also use console command to print it to firebug's console.


2 Answers

If you have Google Chrome, open up the Developer Tools and you can go into the 'scripts' tab, open up your javascript files and look for the click handler.. click along the side of the code to set a breakpoint, then when the code reaches that spot (if you click it, for example), it will pause, and then in the Developer Tools you can see what functions are being called where as you step through the code. You can also hover over any variable in the code window to see its value. Very handy! You can then see if it's getting into your plugin at all (you can do this as well by setting a breakpoint inside the plugin at a place like the first line that will always be accessed when its run).

I believe you can do the same thing with Firebug

It's a bit of a different thinking process to get into (step into, step over, turning breakpoints on and off etc) but it's extremely useful.

A more simple way of checking where problems are occuring is by adding an alert('im working); or something similar to code you're not sure if it's working. You can also alert a variable to see what the value is at that point. You can also use console command to print it to firebug's console. These are doing things that breakpoints/debugging do for you except with the debugging you don't need to change your code.

like image 62
Damon Avatar answered Sep 17 '22 20:09

Damon


If there is a javascript error, then the easies way is using firebug or the Chrome Inspector (right click on the thumbnail and choose "Inspect element"). Open the console tab of either and refresh the page. If there is an error, it will be reported in the console and provide a link to the relevant line.

If there is no error being reported, then the code's logic is preventing the box from being displayed. You'll need to step through the code to find the error. Look at what function is being called from the click handler of the thumbnail image. Go to that function in either tool and place a breakpoint on the first line of the function. Click the thumbnail again and the code will pause on that line. From there you can step through the code and see which code branch is followed. There's likely a sanity check at some point that fails and causes the code to bomb out.

like image 42
Anthony DiSanti Avatar answered Sep 20 '22 20:09

Anthony DiSanti