Meteor.js: <script> tag doesn't work inside <body>

A simple script tag inside the body tag doesn't seem to work. The alert doesn't get triggered in the code below:

<body>
   <script type="text/javascript">
      alert('Hello');
   </script>

      {{>main}}

</body>

Any idea why?

Edit: Just tried it with a fresh meteor app, no alert tag still:

<head>
  <title>test</title>
</head>

<body>

  <script type="text/javascript">
     alert('Hello');
  </script>

  {{> hello}}
</body>

<template name="hello">
  <h1>Hello World!</h1>
  {{greeting}}
  <input type="button" value="Click" />
</template>

Weird thing is when I copy paste the source of the html, made a new html page, and the alert will work.

Edit3: I deployed this app here: http://alert-in-body-test.meteor.com/ Do you get an alert box?


This question is still relevant in the current version of Meteor (version 0.5.4) so I wanted to describe how to include script at the end of the body.

To execute javascript at the end of the body, register a Handlebars helper and put the relevant code there, like this:

In client.html:

<body>
  {{renderPage}}

  {{afterBody}}
</body>

...

In client.js:

if (typeof Handlebars !== 'undefined') {
  Handlebars.registerHelper('afterBody', function(name, options) {
    $('body').append('AFTER BODY');
  });
}

(For a great description of why this is required, see Rahul's answer to a similar question here: https://stackoverflow.com/a/14002991/219238 )


Its working for me

in onrender call this jquery

$.getScript('yours url')


It should work.

I have just pasted this inside one of my projects and it worked.

Your {{>main}} is strange for me tough. Also make sure that <body> is inside <html> tag.

链接地址: http://www.djcxy.com/p/63082.html

上一篇: 拦截Android手机上的传入Flash消息

下一篇: Meteor.js:<script>标记在<body>内不起作用