2

我正在使用 Meteor 开发一个应用程序。我正在尝试在我的一个表单上使用 reCaptcha,并在我的某些页面上使用 Disqus 评论系统。但问题是,当我运行流星服务器时,这些都没有被渲染。

这是我添加到模板中的示例 Disqus 代码:

<script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'HIDDENfromstackoverflow'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> 

为此,网页上仅显示文本“由 Disqus 提供支持的评论”。

对于 reCaptcha:

  <noscript>
     <iframe src="http://www.google.com/recaptcha/api/noscript?k=HiddenFromStackOverflow"
         height="300" width="500" frameborder="0"></iframe><br>
     <textarea name="recaptcha_challenge_field" rows="3" cols="40">
     </textarea>
     <input type="hidden" name="recaptcha_response_field"
         value="manual_challenge">
  </noscript>

有趣的是,如果我在浏览器中将模板作为普通 HTML 文件打开(而不是通过 Meteor 服务器),则会显示 reCaptcha。

我错过了什么?

4

1 回答 1

2

为此,您需要包含 jquery。

公共/disqus.js

 /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'HIDDENfromstackoverflow'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();

应用程序.html

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
</head>

<body>
{{>captcha}}
</body>

<template name="captcha">
    {{#isolate}}
     <div id="my-disqus">
        <div id="disqus_thread"></div>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> 
    </div>
    {{/isolate}}
</template>

客户端/main.js

Meteor.startup (function () {

    $(function () {
        var el = document.createElement("script");
        el.src = "/disqus.js";
        el.type = 'text/javascript';
        $("#my-disqus").prepend(el);

    });

});
于 2013-06-17T16:35:09.960 回答