I am creating a chrome extension. Basically, if the user clicks the content menu button, I want to insert HTML format tags before and after the selected text.
Tags are added to the event page, which, after adding format tags, disables the new value until the contents of the script in the key "insert" the message object.
The code for my content script is as follows:
chrome.runtime.onMessage.addListener(handleRequest)
function handleRequest(message, sender)
{
if (message.paste!==undefined)
{
var newNode = document.createTextNode('');
newNode.innerHTML=message.paste;
var cursor = window.getSelection().getRangeAt(0);
cursor.deleteContents();
cursor.insertNode(newNode);
alert(newNode.innerHTML);
}
}
I thought I was doing it right, because according to this
If a new node is to be added to Node text, then the node is split into an insertion point, and the insertion occurs between two text nodes.
However, the result of clicking the context menu is simply deleting any text. New text is never added, but no errors are printed to the console.
, , .
, , , .
- , ? HTML- node? - , , ?
:
, ( strikethrough). , .
