2017-04-14 39 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"