Print using Menu Button

The print link by default in Knack is currently set to the right side as a link. For new users, they might not be familiar with where to print the page so having it as a menu button would assist in visibility.

Below is an example of what this code will do to a static menu view:

The JS

Add the following code and modify line 12 to the view number.

/***************************************/
/***** Print Menu Button ************/
/***************************************/
function printMenuButton(view_id) {
  $(document).on('knack-view-render.' + view_id, function(event, view, data) {
      $('#' + view_id + ' .knMenuLink').click(function(e) {
        window.print();
      });
  });
}

printMenuButton('view_XXX'); // Set the menu view number

Keep in mind that whatever view you set will apply the window.print() action on click, so keep the print menu button the only button in the menu view.

The CSS

None currently since Menu views on Knack are automatically hidden in print preview.

How to Implement

Add View > Static Menu > Link to a URL

Set URL to javascript:void(0);

Remember the view number (from the URL) and modify the JS code to that view number.

Last updated