Disqus with AJAX

Reload Disqus

by Nic Scozzaro

HTML

<title>Disqus AJAX Test Site</title>

<button onclick="reset('newid1', 'http://example.com/unique-path-to-article1/', 'Article Title 2', 'en');">Load article 1</button>
<button onclick="reset('newid2', 'http://example.com/unique-path-to-article2/', 'Article Title 2', 'en');">Load article 2</button>
<button onclick="reset('newid3', 'http://example.com/unique-path-to-article3/', 'Article Title 3', 'en');">Load article 3</button>
<button onclick="reset('newid4', 'http://example.com/unique-path-to-article4/', 'Article Title 4', 'ru');">Load article 4 (Russian)</button>

<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">blog comments powered by <span class="logo-disqus">Disqus</span></a>

JavaScript

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'physicsisbeautiful';
    var disqus_identifier = 'newid1';
    var disqus_url = 'http://example.com/unique-path-to-article-1/';
	var disqus_config = function () { 
	  this.language = "en";
	};
    /* * * 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);
    })();
    /* * * Disqus Reset Function * * */
    var reset = function (newIdentifier, newUrl, newTitle, newLanguage) {
        DISQUS.reset({
            reload: true,
            config: function () {
                this.page.identifier = newIdentifier;
                this.page.url = newUrl;
                this.page.title = newTitle;
                this.language = newLanguage;
            }
        });
    };