在这里,我能够使用此处找到的函数来获取页面的选定文本,如果没有找到选择,请点击链接,否则什么也不做。
$("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 "";
}