Title: call a javascript function
Last modified: October 8, 2020

---

# call a javascript function

 *  Resolved [jasperkastilan](https://wordpress.org/support/users/jasperkastilan/)
 * (@jasperkastilan)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/)
 * Hi,
    is there a way to call JavaScript functions, every time the lightbox opens
   or closes?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * (@awelzel)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/#post-13509547)
 * No, this is not possible yet.
 * But I may consider adding a hook for custom functions in future updates. What
   exactly is your use case?
 *  Thread Starter [jasperkastilan](https://wordpress.org/support/users/jasperkastilan/)
 * (@jasperkastilan)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/#post-13509671)
 * Thank you for your quick response.
    I’d like to hide/show the scollbar of the
   body.
 *  Plugin Author [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * (@awelzel)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/#post-13509828)
 * Well – this might be a useful feature of the plugin itself.
 * Any pull requests are welcome: [https://github.com/arnowelzel/periodical/](https://github.com/arnowelzel/periodical/)
 * However if you send me the code for this I could also add this manually.
 *  Thread Starter [jasperkastilan](https://wordpress.org/support/users/jasperkastilan/)
 * (@jasperkastilan)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/#post-13510442)
 * Oh great. Nice to hear. I’d realy looking forward to this feature.
    I wrote those
   two functions.
 *     ```
       function hideScrollbar() {
           const scrollbarWidth = window.innerWidth - document.body.offsetWidth;
           document.body.style.paddingRight = scrollbarWidth + "px";
           document.body.style.overflow = "hidden";
           var list = document.getElementsByClassName('list-group');    
       }
       ```
   
 *     ```
       function showScrollbar() {
           document.body.style.paddingRight = 0;
           document.body.style.overflow = "auto";    
       }
       ```
   
 * To call them I have edited the photoswipe.js . I call hideScrollbar() in the ‘
   if(_options.mainClass)’ -clause (line: 920) and showscrollbar() in the ‘destroy:
   function()’. That’s probably not the most elegant solution, but for now it works.
   
   Anyway a hook for custom functions would be nice either. I consider that the 
   topic can be closed.
 *  Plugin Author [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * (@awelzel)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/#post-13511148)
 * Release 3.1.2 contains a slightly modified version of your suggestion which also
   makes use of the internal event system of PhotoSwipe.
 * Are more generic hook might be added in the future: [https://github.com/arnowelzel/lightbox-photoswipe/issues/63](https://github.com/arnowelzel/lightbox-photoswipe/issues/63)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘call a javascript function’ is closed to new replies.

 * ![](https://ps.w.org/lightbox-photoswipe/assets/icon-256x256.png?rev=2906302)
 * [Lightbox with PhotoSwipe](https://wordpress.org/plugins/lightbox-photoswipe/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/lightbox-photoswipe/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/lightbox-photoswipe/)
 * [Active Topics](https://wordpress.org/support/plugin/lightbox-photoswipe/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/lightbox-photoswipe/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/lightbox-photoswipe/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 5 replies
 * 2 participants
 * Last reply from: [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/call-a-javascript-function/#post-13511148)
 * Status: resolved