i was trying to create a js function inside a chrome extension that is supposed to have a string as a parameter and replace every letter of that string to a specific char and it is working if you pass the parameter as : 'con("string is here");' , but if pass as a var that contains the string it doesn't work like : con(varThatHasString);
and chrome console error:
Uncaught TypeError: Cannot read property 'split' of undefined
at con
,
my js:
var letters = [
'q','ض',
'w','ص',
'e','ث',
'r','ق',
't','ف',
'y','غ',
'u','ع',
'i','ه',
'o','خ',
'p','ح',
'a','ش',
's','س',
'd','ي',
'f','ب',
'g','ل',
'h','ا',
'j','ت',
'k','ن',
'l','م',
'z','ئ',
'x','ء',
'c','ؤ',
'v','ر',
'b','لا',
'n','ى',
'm','ة',
'[','ج',
']','د',
';','ك',
',','و',
'.','ز',
'/','ظ',
"'",'ط',
' ',' ',
'1','1',
'2','2',
'3','3',
'4','4',
'5','5',
'6','6',
'7','7',
'8','8',
'9','9',
'0','0'
];//all the used charchters
var lastSelect;// last selected text from page
function con(english) {//convert from english to arabic
var aoutput = new Array;
var chars = english.split('');
for(var i=0;i < chars.length;i++){
aoutput.push(letters[letters.indexOf(chars[i])+1]);
}
var ar = aoutput.join();
var res = ar.replace(/,/g,'');
document.getElementById('copy_box').value = res;
return res;
}
//code will run only when there is text already selected on page
chrome.tabs.executeScript( null, {code:"window.getSelection().toString();"}, function(results){
lastSelect = results[0];
});
con(last_select);
when i run the extension it just doesn't show anything in the text field ,however when i go to the console and try the function itself it works great
and try to con(last_select);
it works great and it shows output in text field