Docsearch redirect without anchor

by maxiloc

HTML

<input type="text" id="docsearch"> 
<link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css" />
<!-- at the end of the BODY -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script>

JavaScript

docsearch({
  apiKey: 'aed6616f628dabf7d0bcbdbe79d6d605',
  indexName: 'insight',
  inputSelector: '#docsearch',
  handleSelected: function (input, event, suggestion) {
  	var url = suggestion.url;
    var url_without_anchor = url.split('#')[0];
    
    window.location.href = url_without_anchor;
  },
  debug: false // Set debug to true if you want to inspect the dropdown
});