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();
});
但它实际上不起作用?还有其他已知的方法吗?