我正在开发一个使用 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 提供支持的评论”出现在网页上。
对于验证码:
<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。
我缺少什么?
为此,您需要包含 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);
})();
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>
客户端/main.js
Meteor.startup (function () {
$(function () {
var el = document.createElement("script");
el.src = "/disqus.js";
el.type = 'text/javascript';
$("#my-disqus").prepend(el);
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)