我正在尝试在我的网站上安装Comodo的TrustLogo...所以,我在部分中有以下内容:
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<script type="text/javascript"> //<![CDATA[
var tlJsHost = ((window.location.protocol == "https:") ? "https://secure.comodo.com/" : "http://www.trustlogo.com/");
document.write(unescape("%3Cscript src='" + tlJsHost + "trustlogo/javascript/trustlogo.js' type='text/javascript'%3E%3C/script%3E"));
//]]>
</script>
这样做的问题在于,当我访问页面 http://localhost:3000 时,主页可以正常加载;
但是,如果我尝试单击任何链接,则页面不会加载;
按下 F5 或刷新按钮后,它可以正常加载。
所以我尝试这样做:
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'https://secure.comodo.com/trustlogo/javascript/trustlogo.js', 'data-turbolinks-track': 'reload' %>
但是这会引起相同的问题。
我尝试更改位置,所以我去到 application.js
并添加了以下内容:
document.addEventListener("turbolinks:load", function(){
var tlJsHost = ((window.location.protocol == "https:") ? "https://secure.comodo.com/" : "http://www.trustlogo.com/");
document.write(unescape("%3Cscript src='" + tlJsHost + "trustlogo/javascript/trustlogo.js' type='text/javascript'%3E%3C/script%3E"));
});
但这给我带来了以下HTML结果(空白页面)
<html>
<head>
<script src="http://www.trustlogo.com/trustlogo/javascript/trustlogo.js" type="text/javascript"></script>
<style type="text/css" media="screen">#comodoTL {display:block;font-size:8px;padding-left:18px;}</style>
</head>
</html>
有什么想法吗?
更新:
根据@patkoperwas的建议将代码移到<head>
之外,但页面仍然是空白的,并在控制台中出现以下错误:
Completed 200 OK in 50ms (Views: 45.6ms | ActiveRecord: 0.9ms)
。 - WeezHard