Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript

JavaScript

Hi,
I have a code that replaces a selected text by the mouse with another text
but I don't know how to get it worked.

my extension.js
_______________________________________

JavaScript
replaceSelectedText("HI");

function replaceSelectedText(replacementText) {
    var sel, range;
    if (window.getSelection) {
        sel = window.getSelection();
        if (sel.rangeCount) {
            range = sel.getRangeAt(0);
            range.deleteContents();
            range.insertNode(document.createTextNode(replacementText));
        }
    } else if (document.selection && document.selection.createRange) {
        range = document.selection.createRange();
        range.text = replacementText;
    }
}


_____________________________________
my Manifest.json


JavaScript
{
  "name": "Translator",
  "version": "1.0",
  "manifest_version": 2,
  "description": "This Extention helps you to translate",
  "author": "Ayman Ghandour",
  "browser_action": {
    "default_title": "Translator",
    "default_icon": {
      "38": "80.png"
    }
  },
  "permissions": [
    "


What I have tried:

I have tried to load the extension but when I select any text it's not changed to HI.
please help me ..

thanks a lot
Ayman
Posted
Updated 12-Oct-16 7:41am
v6
Comments
Did you debug?
Ayman Ghandour 11-Oct-16 10:52am    
Hi, there is no Inspect: Background Page so I don't know how to debug
Click F12 and check.
Ayman Ghandour 12-Oct-16 11:06am    
I opened the Developer Tools but when I click the extension icon nothing happened... ( I clicked "Break on unhandled exceptions" )
Ayman Ghandour 12-Oct-16 13:04pm    
Hi Tadit,
Can you please check that this code that I wrote works in Chrome or Edge extensions, and if not... what should I need to change ?
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900