3

Uservoice asks you to load async their widget on page load which the code looks like this:

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

And then they give you the option to run their widget on click as such:

javascript:UserVoice.showPopupWidget();

What if I dont want to load their widget once the page is loaded at all only when the user clicks on the link?

I would assume something like this:

 $('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();

   });

But it doesnt actually work? is there any other known way?

2 Answers 2

5

Try this:

$('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
    );
});
5
  • This looks about right (with the edit I made). What it does is it uses jQuery to load and add the script to the page, and as soon as that script is loaded, the callback to show the popup widget is called.
    – AKX
    Commented Feb 27, 2012 at 12:28
  • And with the additional edit, the UserVoice script should never be loaded twice.
    – AKX
    Commented Feb 27, 2012 at 12:30
  • Any idea what the deal is with that random js filename? cyoJokWhM5SEW9I3h3oBFQ.js. I am reluctant to hard code that into my scripts as it looks like something that might change. Any advice? Commented Feb 9, 2013 at 15:16
  • @GwynHowell I think the filename corresponds to the settings in UserVoice admin page: default tab selection, widget mode, etc.
    – Yeonho
    Commented Jun 8, 2013 at 17:32
  • I my project we are using user voice api for that I have to edit few things in my java script file( cyoJokWhM5SEW9I3h3oBFQ.js).How can I do this.
    – phani
    Commented Jun 20, 2018 at 11:53
0

Try this

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

see here for more details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.