1

I'm having trouble with a bit of script in getting ColorBox to work on my site.

Originally it was coded to override the default link follow 'launch(this);' whenever the class .boxElement was found on a link.

I've tried to modify it so that the override only happens when it is not the homepage, but it doesn't seem to trigger. Instead it just prevents the override on all pages.

$('.' + boxElement, document).live('click', function (e) {
   if ( !is_home() ) {
       e.preventDefault();
       launch(this);
   } else { return true; }
});

Could anyone provide some assistance? I'm sure it is a simple mistake.

5
  • 6
    Can you show us your is_home() function please?
    – BenM
    Feb 20, 2013 at 11:52
  • 2
    The .live() function has been deprecated for months now (since jQuery 1.7 was released), and was removed entirely in 1.9. You should switch to using either .on() (1.7+) or .delegate() - view the docs for .live() for details on converting from one to the other. Feb 20, 2013 at 11:56
  • 1
    @BenM - I have a funny feeling this is a PHP and JS mashup. is_home() is a built in Wordpress PHP function. Am I right Taylor?
    – McNab
    Feb 20, 2013 at 11:57
  • 1
    Indeed, that's what I was thinking too!
    – BenM
    Feb 20, 2013 at 11:58
  • @McNab - Indeed indeed, that was the error. I am new, lost, and confused :/ Alen's answer below put me onto the right track. Thank you guys so much, it truly is appreciated.
    – Taylor
    Feb 20, 2013 at 12:05

1 Answer 1

5

This function should return true for your home page

   var is_home = function(){
      return window.location.href.indexOf("some_part_of_home_url") > -1;
   }
1
  • 1
    Perfect, thank you. As @McNab pointed out I was mixing up my code a little bit. Thanks a bunch, it is truly appreciated!
    – Taylor
    Feb 20, 2013 at 12:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.