문제

I have SPA pages that uses durandaljs and knockoutjs. Now I am going to implement a support of disqus plugin for my site.

When I added disqus I have found that the same comments is showing up for different pages with different URL (I used durandal for URL rewriting).

I guess that root of this issue is that my rewrote URL's are distinguished by full hashbang(#!) enter image description here

The code is following:

    var disqus_shortname = 'somename';
    var disqus_identifier = context.id;

    (function () {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    if (typeof DISQUS != 'undefined') {
        DISQUS.reset({
            reload: true,
            config: function () {
                this.page.title = "title" + context.id;
                this.page.identifier = context.id;
                this.page.url = "http://localhost:23054/#!ideas/details/" + context.id;
                debugger;
            }
        });
    }

View:

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

I hope somebody uses disqus comments with SPA pages and knows how to help me to solve this.

도움이 되었습니까?

해결책

here's my solution:

    var id = context.id;
    disqus_shortname = 'somename',
    disqus_identifier = id,
    disqus_title = id,
    disqus_url = "http://someurl.com/#!" + id;
        if ($('head script[src="http://' + disqus_shortname + '.disqus.com/embed.js"]').length == 0) {
            (function () {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0]).appendChild(dsq);
            })();
        }
        if (typeof DISQUS != "undefined") {
            DISQUS.reset({
                reload: true,
                config: function () {
                    this.page.identifier = id;
                    this.page.url = "http://someurl.com/#!" + id;
                }
            });
        }

다른 팁

I think the problem may be that your identifier isn't unique enough. From the Disqus documentation:

When Disqus-enabled pages are visited, Disqus uses this identifier to determine the appropriate comment thread to load. If the appropriate thread could not be found, a new thread is created.

I'm not sure what context.id is, but make sure that this is unique for each thread and unique enough for Disqus' purposes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top