sachinchoolur / lightGallery

A customizable, modular, responsive, lightbox gallery plugin.
https://www.lightgalleryjs.com/
Other
6.42k stars 1.28k forks source link

share to facebook #1057

Closed rihamNasleh closed 3 years ago

rihamNasleh commented 3 years ago

Hello I need some help to edit sharing feature 1 in current version, sharing on facebook button shares the whole page, not the current active image so to complete this action I should change the meta tag content to be changed dynamically I add to "v1->lightgalleryjs->lg-thumbnail.js" these 3 lines of code at the end of this function _this.core.$el.on('onBeforeSlide.lg.tm', function() { $thumb.removeClass('active'); $thumb.removeAttr('id'); $thumb.eq(_this.core.index).addClass('active'); //the new 3 lines var newValue = 'www.mydomainname.s'+ $thumb.eq(_this.core.index).find('img').attr('src').replace('..', '');

        $('meta[property=og\\:url]').attr('content', newValue);
        $('meta[property=og\\:image]').attr('content', newValue);
    });

and the value changed -check the attached image- , but did not work! just continue with the first meta tage content value that assigned at the head . plz help me to find solution to this issue

Thanks in regards

sachinchoolur commented 3 years ago

Hey @rihamNasleh,

I don't think this is possible.

It’s not possible to modify the meta tags using javascript simply because the facebook “scraper” doesn’t run the javascript in the pages it scrapes. It reads the html as-is. The only way to modify the meta tags dynamically is to dynamically create the html page itself.

References

This is not a lightGallery problem. This is how Facebook processes the content.

Closing the issue. Please let me know if you have any other questions