google chrome - Can't access JavaScript variable inside function -
i'm making extension selected text search in different search engines. 1 of menu items changes if selected string particular one. have done far , want, except can not create "title" of menu change. how give value variable "mytitle" in if statement within function?
thanks in advance.
var mytitle; // if give value here work, need value based on if statement bellow. function myfunction(selectedtext) { if(selectedtext.match (/somestring|someotherstring/)) { var myurl1 = 'https://someurl' + selectedtext; chrome.tabs.create({url: myurl1}); mytitle = "title1"; //i can not create variable value here }else{ var myurl2 = 'https://someotherurl' + selectedtext; chrome.tabs.create({url: topiccall}); mytitle = "title2"; //i can not create variable value here } } chrome.contextmenus.create({ **"title": mytitle,** // should alter based on selection contexts:["selection"], onclick: function (info)myfunction(info.selectiontext);} });
you have "cause , effect" mixed up. when chrome.contextmenus.create
called, myfunction
has not executed yet , value of mytitle
has not been assigned.
javascript google-chrome
No comments:
Post a Comment