3

Uservoice 要求您在页面加载时异步加载他们的小部件,代码如下所示:

var uvOptions = {};
          (function() {
            var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
            uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/loremipsum.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
          })();

然后他们为您提供了在点击时运行他们的小部件的选项,如下所示:

javascript:UserVoice.showPopupWidget();

如果我不想在页面加载后仅在用户单击链接时加载他们的小部件怎么办?

我会假设是这样的:

 $('selector').click(function () {

         var uvOptions = {};
          (function() {
            var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
            uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/cyoJokWhM5SEW9I3h3oBFQ.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
          })();
       javascript:UserVoice.showPopupWidget();

   });

但它实际上不起作用?还有其他已知的方法吗?

4

2 回答 2

5

尝试这个:

$('selector').click(function () {
    var uvOptions = {};
    var showWidget = function() { window.UserVoice.showPopupWidget(); };
    if(window.UserVoice) return showWidget(); // Loaded already
    $.getScript(
       ('https:' == document.location.protocol ? 'https://' : 'http://') +
       'widget.uservoice.com/cyoJokWhM5SEW9I3h3oBFQ.js',
       showWidget
    );
});
于 2012-02-27T12:13:47.477 回答
0

尝试这个

<a href="http://back-up-url-goes-here.com" data-uv-trigger>Contact us</a>

这里了解更多详情

于 2015-02-05T11:23:41.183 回答