1

我加载并显示 DISQUS 被剪断,在 AJAX 提供的页面上轻松重新加载它

var id = this.getIdentifier(),
        disqus_shortname = 'myportal',
        disqus_identifier = id,
        disqus_title = id,
        disqus_url = "http://" + document.domain + "/#!" + 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
        });
}

然而,尝试在其他 url(相同的)中加载相同的线程会产生空白(新)disqusion。

尝试在它们两个上加载相似的线程:

var id = "Disqusion about coding";
DISQUS.reset({
        reload: true,
        config: function () {
                this.page.identifier = id;  
                this.page.url = "http://myportal.com/#!" + id;
        }
});

给予单独的新威胁。

4

2 回答 2

1

如果您完全关闭 URL 并仅使用标识符,则此代码似乎有效。此外,disqus_shortname disqus_identifier并且disqus_url可能应该是window上下文的一部分。(我在任何地方都找不到这个文档,但我在模块中发现了一些奇怪的边缘案例)

    var disqus_shortname = 'myportal',
    disqus_identifier = 'UNIQUE_IDENTIFER';

    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
            });
    }

http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables

http://help.disqus.com/customer/portal/articles/472095-how-do-i-load-the-same-thread-of-comments-on-multiple-pages-

于 2013-10-27T05:05:40.513 回答
0

I've resolved it by myself with timer - am checking for dsq object and as soon it's found I handle it and stop timer. Code for reference:

//
//
//
this.getIdentifier = function () {
    var identifier = $(sel_product).val() + '-' + $(sel_model).val();

    identifier = identifier.replace(/^\s+|\s+$/g, '').split(' ').join('_');

    return identifier;
};

//
//
//
this.loadDisqus = function () {
    var timerID = 'DisqusComments.loadDisqus';

    if ($(__selector_DisqusBox).length > 0) {
        var id = inst.getIdentifier(),
            disqus_shortname = 'shortnameid',
            disqus_identifier = id,
            disqus_title = id,
            disqus_url = "http://" + document.domain + "/#!" + id;

        Utilities.handleTimedEvent(timerID, callself(this, function () { disqusReset(); }), null, 100);

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

    function disqusReset() {
        if (typeof DISQUS != 'undefined') {
            DISQUS.reset({
                reload: true,
                config: function () {
                    this.page.identifier = disqus_identifier;
                    this.page.url = disqus_url;
                    this.page.title = disqus_title;
                }
            });

            Utilities.clearTimedEvent(timerID);
        }
    }

    disqusReset();
};
于 2014-03-22T09:22:57.620 回答