2017-04-14 41 views
0

当使用Turbolinks 5和默认Disqus评论嵌入代码时,您将在控制台中看到“浏览器不支持”错误和警告:“使用DISQUS。请重置,而不是重新加载embed.js。“Disqus评论在Turbolinks导航时显示“浏览器不支持”5

在Disqus文档中使用AJAX示例时,embed.js警告消失,但不会显示“浏览器不支持”警告。

如何解决此问题而不禁用Turbolinks?

回答

1

要解决这个问题,请使用默认Disqus嵌入代码:

<div id="disqus_thread"></div> 
<script> 

/** 
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. 
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/ 
/* 
var disqus_config = function() { 
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable 
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable 
}; 
*/ 
(function() { // DON'T EDIT BELOW THIS LINE 
var d = document, s = d.createElement('script'); 
s.src = 'https://EXAMPLE.disqus.com/embed.js'; 
s.setAttribute('data-timestamp', +new Date()); 
(d.head || d.body).appendChild(s); 
})(); 
</script> 
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> 

并添加此:

s.setAttribute('data-turbolinks-track', 'reload'); 

因此,代码变为:

<div id="disqus_thread"></div> 
<script> 

/** 
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. 
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/ 
/* 
var disqus_config = function() { 
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable 
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable 
}; 
*/ 
(function() { // DON'T EDIT BELOW THIS LINE 
var d = document, s = d.createElement('script'); 
s.src = 'https://EXAMPLE.disqus.com/embed.js'; 
s.setAttribute('data-timestamp', +new Date()); 
s.setAttribute('data-turbolinks-track', 'reload'); 
(d.head || d.body).appendChild(s); 
})(); 
</script> 
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> 

Here is the Turbolinks documentation about data-turbolinks-track="reload"