0

I'm trying to load a custom javascript for cloudzoom on desktops and a other one for touch devices.

In my i have this piece of code:

        if ("ontouchstart" in document.documentElement){
            // It's a touch screen device.
           $.getScript('/js/cloud-zoom.1.0.2.min.js'), 
               $(function() {
                  alert('iPad Load was performed.');
                });
        }
        else {
            $.getScript('/js/cloud-zoom.1.0.2.custom.js'), 
            $(function() {
              alert('Custom Load was performed.');
            });
        }

This works fine. But when i remove the alert the script will not load... I don't get a error in the console of firefox either. How can i make it work without alerting something.

1 Answers1

4

You have a syntax error.

You wrote

$.getScript(...),
$(function() { });

The , is invalid and should not be there.

If you want to pass a script callback, write

$.getScript("...", function() { ... });
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • The problem is that this: `else { $.getScript('/js/cloud-zoom.1.0.2.custom.js'); }` is not working. And the script does get loaded when i use the above code. When i try: `$.getScript('/js/cloud-zoom.1.0.2.custom.js', function() { alert('Custom Load was performed.'); });` i dont get anything at all. No error no alert en no functioning cloudzoom. – PatrickWolf May 04 '12 at 13:34
  • What do you see in the Net tab? What happens if you set Break on all Exceptions? – SLaks May 04 '12 at 13:38
  • /js/cloud-zoom.1.0.2.custom.js?_=1336138844596 4ms. What do you mean with break? – PatrickWolf May 04 '12 at 13:47
  • Do you see a response for that? Do you see it in the Scripts tab? – SLaks May 04 '12 at 13:49
  • There is a Break on all Exceptions button in the upper right corner of the Console tab. – SLaks May 04 '12 at 13:49
  • It is in the XHR tab. Not in de Scripts tab. Don't know why – PatrickWolf May 04 '12 at 14:02