Active
Project:
fancyBox
Version:
6.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
20 Sep 2011 at 18:51 UTC
Updated:
7 Dec 2025 at 22:57 UTC
I encountered the following Javascript error in fancybox.js (see attached screenshot). Firefox ignored the error and initialized Fancybox correctly, but Safari caught the error and Fancybox failed to load. I don't know how to roll a proper patch, so I'll just explain how I fixed the problem:
I changed line 11 of fancybox.js from:
if (settings.options[events[i]].length && typeof(settings.options[events[i]]) == 'string') {
to:
if (typeof(settings.options[events[i]]) != 'undefined' && typeof(settings.options[events[i]]) == 'string' && settings.options[events[i]].length) {
It seems that settings.options[events[i]].length was throwing an error because settings.options[events[i]] was evaluating to "undefined", and therefore was not an object. I simply added a check to ensure that it's not "undefined", before attempting to retrieve the object's length property.
I hope this helps!
| Comment | File | Size | Author |
|---|---|---|---|
| fancybox-js-error.jpg | 130.19 KB | Anonymous (not verified) |
Comments
Comment #1
Island Usurper commentedIt should be ok just to make the typeof() == 'string' check first, without seeing if it's 'undefined'.
This fix is necessary because of the way for() works in JavaScript. Not only is
i0, 1, 2, 3, etc., but it also gets 'filter', and 'length'. As quirky as PHP is, in many ways JavaScript is worse.