Insert a "Go Back" button

I was looking for a way to "Go Back" to the previous screen, in this case for a number of drill-down reports. The script inserts a button with go-back function to the current view, as determined by "view.key".

// Add go back button to a set of views
$(document).on("knack-view-render.any", function(event, view) {
var appviews=["view_32","view_43","view_62"];
var key=(view.key!=undefined)?view.key.toLowerCase().trim():"";
var l=appviews.length;
for (var x=0; x<l; x++) {

if (appviews==key) {
$(’#’+appviews).prepend("<button id=‘button’>Go Back</button>");
document.getElementById(‘button’).addEventListener(‘click’, function() {

}; // if
}; // for

//Here is a simpler take where you have more control over the button placement.

//Just add this html to a rich text view after clicking on the html editor wherever you want  a back button to appear.

/*<button id="back-button" type="button" style="padding: 0 10px; line-height: 22px;" class="kn-button">Back</button>*/

//Then add this to the js console.
$(document).on("knack-scene-render.any", function(event, scene) {


console.log('button clicked');