When I select text in the browser and click the context menu I want to get HTML content from the selected text
Here is my code,
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId === "menu1") {
var html = getSelectionHtml();
}
});
I have tried this function but its uses for web
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
return html;
}
Hello World
Welcome