Here we go, I was able to figure it out using the function found here , to get the selected text, if no choices were found, follow the link otherwise do nothing.
$("td").click(function() { var sel = getSelected().toString(); if (sel === "") { var brand = $(this).closest("tr").attr("data-brand"); var url = window.btoa(window.location.toString()); window.location = "?page=sku&action=brand&brand=" + brand + "&b=" + url; } }); function getSelected() { if (window.getSelection) { return window.getSelection().toString(); } else if (document.getSelection) { return document.getSelection().toString(); } else { var selection = document.selection && document.selection.createRange(); if (selection.text) { return selection.text.toString(); } return ""; } return ""; }
source share