How to call – user151496 Feb 13 '16 at 18:23

  • You cannot **call** a ` – Felix Kling Feb 13 '16 at 18:32
  • Accept the answer that worked for you, to let others know if they have a similar problem. – ReinstateMonica3167040 Jul 26 '17 at 22:17
  • 1 Answers1

    1

    To dynamically include(load) an external javascript file to the page on certain button click event:

    html part:

    <button class="getscript">Load script</button>
    

    js part:

    document.querySelector('button.getscript').addEventListener('click', function(e){
        var script = document.createElement("script");
        script.type = "text/javascript";
    
        script.src = "//massage.book.me/iframe/pm_loader_v2.php?width=960&url=//massage.book.me&theme=bootstrap__square_rainbow__colored_light&layout=bootstrap__square_rainbow&timeline=modern&mode=auto&mobile_redirect=0&hidden_steps=event,unit&event=1&unit=1";
    
        document.getElementsByTagName("head")[0].appendChild(script);
        e.preventDefault();
    })
    
    RomanPerekhrest
    • 88,541
    • 4
    • 65
    • 105
    • 1
      If this is really what the OP wants (pretty unclear from the question), then it's a duplicate of [Include a JavaScript file in another JavaScript file?](http://stackoverflow.com/q/950087/218196) and should be closed as such. In general, please don't encourage low quality questions by answering them. – Felix Kling Feb 13 '16 at 18:32
    • @FelixKling, let's wait to see what the OP really intended, then you may close it – RomanPerekhrest Feb 13 '16 at 18:34
    • Tks RomanPerekhrest. I will be back in office tomorrow where I will be able to try. I will post what happen but I got the idea. *** For the records if human been was not greedy as Felix this planet would be much better. I believe he don't get the main idea of GNU when he stated "...don't encourage low quality questions by answering them." – Robert Barros Feb 15 '16 at 01:25