I've created/adapted a highlight function using JS/jQuery. Which takes the terms after the query string '?search=
' in the address bar and highlights all those terms on a section of the page a hue of yellow. (It also collapses the panel on the page too) I've tried this in dev mode and it worked a treat. However, when it's in production it keeps crashing the browser window and I really can't figure out why. Any assistance with this is greatly appreciated.
Thanks in advance.
function highlightTerm() {
var url = window.location.href;
var index = url.indexOf("qaisearch=");
if (index != -1) {
var term = url.substr(index + 10);
term = decodeURIComponent(term);
var srchStr = $("div.col-md-9").html();
var pattern = new RegExp("(" + term + ")", "gi");
term = term.replace(/(\s+)/, "(<[^>]+>)*$1(<[^>]+>)*");
srchStr = srchStr.replace(pattern, "<mark>$1</mark>");
srchStr = srchStr.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1</mark>$2<mark>$4");
$("div.col-md-9").html(srchStr);
$('.panel-default > .panel-collapse').toggleClass('in');
}
}
highlightTerm();