skip to Main Content

I’m using this code to load twitter’s web intent javascript functionalities only and only if the share modal is opened:

$(function(){
    $('#share').on('show.bs.modal', function(e){
        if(typeof(twttr) === 'undefined') {
            $.getScript('https://platform.twitter.com/widgets.js');
        }
    });
});

It works great. Now, I also want to completely remove the show.bs.modal event from the modal once it has been triggered for the first time, because it will be completely unnecessary afterwards.

I already tried:

$('#share').off('show.bs.modal');

but I’m guessing that since it’s not a standard event, it won’t work like that. Also, I’ve searched for event removal methods in the bootstrap docs, but it doesn’t seem to be anything like that in there.

Any ideas? Thanks!

2

Answers


  1. I guess it’s all about event type of modal window.

    Probably you meant shown.bs.modal instead of show.bs.modal.

    $(function(){
        $('#share').on('shown.bs.modal', function(e){
            if(typeof(twttr) === 'undefined') {
                $.getScript('https://platform.twitter.com/widgets.js');
            }
        });
    });
    
    $('#share').off('shown.bs.modal');
    
    Login or Signup to reply.
  2. $('#share').on('shown.bs.modal', function(e){
        $('#share').off('shown.bs.modal');
        $.getScript('https://platform.twitter.com/widgets.js');
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search