The alt attribute of an image is not available from inside Fancybox and can't be passed to it either (without adapting fancybox.js). That's why this.alt
in your second call to beforeShow()
returns undefined
.
You would need to use another method to pass the desired string to your Facebook link. If the alt text is the same as the title text, how about doing something like:
if (this.title) {
// pass original title to new variable
var originalTitle = this.title;
// New line
this.title += '<br />';
// Add tweet button
this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-url="' + this.href + '">Tweet</a> ';
// Add FaceBook like button ## using originalTitle
this.title += '<a href="https://www.facebook.com/sharer/sharer.php?s=100&p[url]=' + this.href + '&p[title]=' + originalTitle + '&p[images][0]=' + this.href + '&p[summary]=My website summary">Facebook</a> ;'
}
The alt attribute is not allowed in anchor tags - is there any reason for it being there?