Dynamically change the src of a script tag

前端 未结 1 1697
萌比男神i
萌比男神i 2021-01-22 16:52

I\'ve read some of the similar questions but they don\'t quite answer this query of mine.

I am building a website that uses Viddler video hosting. In their embed code yo

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 17:22

    With jQuery you can load and execute JavaScript on demand. Before loading the script, append the playlist part to the script url like this:

    HTML

    Play list A
    Play list B
    Play list C
    

    jQuery

    $(".playlist-link").click(function(e){
        e.preventDefault();
        var playlist = $(this).attr("href");
    
        var url = 'http://www.viddler.com/tools/vidget.js' +
                      '?widget_type=js_list' +
                      '&widget_width=940' +
                      '&source=playlist' +
                      '&user=USERNAME ' +
                      '&playlist='+ playlist +
                      '&style=grid'+
                      '&show_player=true'+
                      '&player_type=simple'+
                      '&max=12'+
                      '&videos_per_row=6'+
                      '&v=2.0'+
                      '&id=XXXXXXXXXX';
    
        $.getScript(url, function(data, textStatus){
            alert('This is executed after your script is loaded');
        });
    });
    

    0 讨论(0)
提交回复
热议问题