0

I have this script calling a lightbox to trigger if the URL is site.com/page.html?globe=1 and it is not working here is the code:

var $j = jQuery.noConflict();
$j(document).ready(function() {
    var url = window.location.href;
    url = url.toLowerCase();
    if (url.indexOf('globe=1') != -1) {
        $j("a#fancy").fancybox({
            'padding' : 0,
            'overlayShow' : false,
        });
    }
}
});
$j("a#fancy").fancybox({
    'padding' : 0,
    'overlayShow' : false,
});

What is wrong and why does it not work? I have used this before for other scripts other than fancybox and I assume I am typing some code wrong.

3
  • Where is the fancybox function you're calling if globe=1 is present in the URL? Commented Oct 26, 2011 at 8:52
  • I added code and tried that did not work. Commented Oct 26, 2011 at 8:57
  • url.indexOf('globe=1') isn't fail proof. It would also trigger for ?GoogleGlobe=123; Commented Oct 26, 2011 at 12:30

2 Answers 2

2
var $j = jQuery.noConflict();
$j(document).ready(function() {
    var url = window.location.href;
    url = url.toLowerCase();
    if (url.indexOf('globe=1') != -1) {
        $j("a#fancy").fancybox({
            'padding': 0,
            'overlayShow': false // extra comma removed
        });
    }
}); // extra curly bracket removed
$j("a#fancy").fancybox({
    'padding': 0,
    'overlayShow': false // extra comma removed
});

There were few errors - a bracket, and 2 commas. Use visual IDE to track the brackets.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use:

if(location.search === '?glob=1') { /* YOUR FANCYBOX CODE HERE */}

If glob=1 is the only parameter otherwise use:

if(location.search.search('glob=1') !== -1) { /* YOUR FANCYBOX CODE HERE */}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.