1
Good evening, the problem is this:
I’m doing an extension for Chrome it works as follows:
as soon as the page loads, inserts emoticons images for when someone clicks on them, load the emoticons into the textarea. Only a mistake happens as follows:
When the extension loads appear the emoticons and I click them to add in the textarea, in the console appears the message that the function has not been defined.
Now, if I reach the paste console and runs the javascript, it works perfectly without any error.
Does anyone have any idea what might be going on?
Link containing the javascript:
function teste(obj) {
if (obj == "Agonia") {
document.querySelector('textarea').innerText='[:(]'
}else if(obj =="Cool"){
document.querySelector('textarea').innerText='[8)]';
}
else if(obj =="Irritado"){
document.querySelector('textarea').innerText='[:x]';
}
else if(obj =="Feliz"){
document.querySelector('textarea').innerText='[:)]';
}
else if(obj =="Piscada"){
document.querySelector('textarea').innerText='[;)]';
}
else if(obj =="Sorrisao"){
document.querySelector('textarea').innerText='[:D]';
}
else if(obj =="Surpreso"){
document.querySelector('textarea').innerText='[:o]';
}
else if(obj =="Lingua"){
document.querySelector('textarea').innerText='[:P]';
}
else if(obj =="Doido"){
document.querySelector('textarea').innerText='[/)]';
}
}
document.getElementsByTagName("td")[2].innerHTML='<a href=javascript:teste();><img src="http://app.e-orkut.com/assets/images/emoticons/2.gif"> '
+'<a href=javascript:teste("Cool");><img src="http://app.e-orkut.com/assets/images/emoticons/1.gif"></a>'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/3.gif">'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/4.gif">'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/5.gif">'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/6.gif">'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/7.gif">'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/8.gif">'
+'<img src="http://app.e-orkut.com/assets/images/emoticons/9.gif">';
I thank all who can help in some way.
Where are you putting that code on the page? A full-page Pastebin would be better. You’re putting that code inside a function
onload
or.ready(
?– Sergio
As far as I know the Javascript running on the page cannot interact directly with the extensions' scripts, so much so that there is a specific API only for exchanging messages. If you are putting some code on the page that tries to call a declared function in the extension it will not work. However, you can inject your role code into the page. Unfortunately I don’t have the code of how to do this, only know that it is possible because I followed the development of an extension at work.
– utluiz
The function is being called inside the head. What I do not understand is that if I run the script on the browser console, can call the function quiet. This extension basically adds a href that the person clicks and adds an emoticom to the texarea
– Santiago Moreira
For example: extension when starting loads a <a href=function();> click <a/> inside a site div near the textarea, when the clicker inserts the emoticom into the textarea. Ready. As I said by the console works, now by the extension when it loads no.
– Santiago Moreira
Post the HTML part so we can better understand how the code works.
– Guilherme Nascimento