Javascript API


Saber Feedback’s Javascript API allows you to interact with and control Saber Feedback through the global window.Saber object.

Here’s a full example of installing the API and setting an option:

<script type="text/javascript">
  (function(){
    window.Saber={com:[],do:function(){this.com.push(arguments)}};
    var e = document.createElement("script");
    e.setAttribute("type", "text/javascript");
    e.setAttribute("src", "//feedback.saberfeedback.com/feedback.js?api_key=[YOUR API KEY HERE]");
    document.getElementsByTagName("head")[0].appendChild(e);
  })();
  
  // Set Saber to show in French
  Saber.do('set_option', 'language', 'fr');
</script>

open

The open method opens the Saber Feedback interface in exactly the same way as when the feedback button is clicked. If the feedback interface is already open nothing will happen.

If you have specified an on_open event handler, this will be triggered.

There are no arguments passed to the open method.

Saber.do('open');

close

The close method closes the Saber Feedback interface in exactly the same way as when the feedback interface is cancelled. If the feedback interface is not currently open nothing will happen.

If you have specified an on_close event handler, this will be triggered.

There are no arguments passed to the close method.

Saber.do('close');

set_options

The set_options method allows you to set runtime options after Saber Feedback has been loaded.

The options should be passed as a hash object to the set_options method.

Saber.do('set_options', {
  language: 'fr', // set the language to French
  feedback_values: {
    'Email': '[email protected]' // set default value for email field
  }
});

set_option

The set_option method is a convenience method that allows you to set a single run time option.

set_option requires two arguments, the option name, and its new value.

Saber.do('set_option', 'languge', 'fr'); // set the language to French