I’m trying to fix a minor bug in my lightbox Javascript, whilst keeping the edit as unobtrusive as possible.
Example page:
http://www.mattressonline.co.uk/Product/Silentnight-Miracoil-3-Gold-Label-Limited-Edition-Mattress-P43
The issue is with the main product image. If you click on either of the two thumbnails, the images load inside the lightbox as expected. Clicking on the large image fires an event that clicks on the gallery image, and you can see the lightbox begin to pop up, but then the default event for an <a> tag fires off, and the image loads in a separate window. This shouldn’t happen, since the link uses return false;
<a id="gallery-link" class="main" href="#" onclick="click($('gallery-image-0')); return false;" title="Gold Label Mattress">
<img id="gallery-image" src="/content/products/280x175/silentnight-ariel-miracoil-gold-label-limited-edition.jpg" alt="Gold Label Mattress">
</a>
Apart from that, it’s pretty much just a standard prototype/scriptaculous/lightbox2 setup.
Any idea why return false isn’t returning false? It’s incredibly frustrating.
Edit: IE6 and 8 DO return false as told. Current Firefox, Chrome, and IE9 don’t.
You are attempting to return false after another event has been fired off which has its own set of actions. So, you plan on calling
return falsebut before you do,gallery-image-0responds to yourclick()call which may have already caused the browser to open another page.Does that make sense? So, you need to observe
clickon the target element and also make sure it ends withreturn falseorevent.stop().