Using Disqus / reCaptcha in a Meteor Application

时光毁灭记忆、已成空白 提交于 2019-12-08 01:38:54

问题


I'm working on an application using Meteor. I am trying to use reCaptcha on one of my forms, and also the Disqus comments system on some of my pages. But the problem is, none of these are being rendered when I run the meteor server.

Here's the sample Disqus code I'm adding to my template:

<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> 

For this, only the text "comments powered by Disqus" shows up on the webpage.

For the 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>

It's interesting to note that the reCaptcha is displayed if I open my template as a normal HTML file in the browser (and not via the Meteor server.)

What am I missing?


回答1:


You need jquery included for this.

public/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);
        })();

app.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>

client/main.js

Meteor.startup (function () {

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

    });

});


来源:https://stackoverflow.com/questions/17150201/using-disqus-recaptcha-in-a-meteor-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!