Skip to content Skip to sidebar Skip to footer

Triggering Script Via Url

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(

Solution 1:

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.

Solution 2:

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 */}

Post a Comment for "Triggering Script Via Url"