user3674611
user3674611

Reputation:

Loading JavaScript code inside body meteor

The code only seems to work when I add it to the head.

<script type="text/javascript" src="http://ad.leadboltmobile.net/show_app_ad.js?section_id=00000000"></script>

I tried other answers, but they seem to be outdated for meteor 1.0.

Thanks.

Upvotes: 1

Views: 167

Answers (2)

Sasikanth
Sasikanth

Reputation: 3043

we can load js files in meteor i couple of ways

1) using irlibloader package

Router.route('codeEditor',{
    waitOn: function(){
        return [IRLibLoader.load('https://some-external.com/javascript.js'), IRLibLoader.load("smthels.js")]
    }
  });

2)as said above using getscript

 $.getScript("'https://some-external.com/javascript.js", function() {
    //callbcak function
  });

I think, using script tag in the head section will load the file in all pages

More Info: http://www.meteorsnippets.com/blog/add-external-scripts-in-meteor

Upvotes: 1

saimeunt
saimeunt

Reputation: 22696

You can try loading your JS script using jQuery :

// Meteor startup triggered when DOM is ready
Meteor.startup(function(){
  $.getScript("//ad.leadboltmobile.net/show_app_ad.js?section_id=00000000",function(){
    // script loaded here !
  });
});

Upvotes: 2

Related Questions