Reputation: 4267
I'm writing a google chrome extension . it has two textareas and a button . once the button is clicked , it takes the code from the first textarea , does some logic on it and then pasts and shows the output in the second textarea . it works fine when I open the .html file in the browser but when I wanna use it as an extension it doesn't function and when I click the button nothing happens . I think it's got something to do with permissions , I've already put : "contextMenus",
"clipboardRead",
"clipboardWrite" permissions on my manifest file but it still doesn't work .
I'll appreciate if someone can help me with this .
thanks
edit : codes
manifest.json :
{
"name": "MissLang Fix extension",
"manifest_version": 2,
"version": "1.0",
"description": "fixing english to farsi typings.",
"icons":{
"128":"icon_128.png"
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "missLangFix.html"
},
"permissions": [
"contextMenus",
"clipboardRead",
"clipboardWrite"
]
}
missLangFix.html :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
<script src="script.js"></script>
<title>MissLang Fix</title>
</head>
<body>
<center>
<div id="test"></div>
<textarea class="txtarea" id="input" rows="4" cols="50"></textarea>
<!--<div class="myBtn" onClick="myClick()">
<b style="line-height:30px">fix</b>
</div>-->
<br/>
<input type="button" value="fix" onclick="myClick()" />
<br/>
<textarea class="txtarea2" id="output" rows="4" cols="50" readonly="readonly"></textarea>
</center>
</body>
</html>
script.js :
window.onload = myOnload();
function myOnload(){
var myString = document.getElementById("txtarea").innerHTML = "";
}
function myClick(){
var myString = document.getElementById("input").value;
for(var i=0;i<myString.length;i++){
myString = myString.replace("q","ض");
myString = myString.replace("w","ص");
myString = myString.replace("e","ث");
}
//document.getElementById("txtarea").value = myString;
document.getElementById("output").innerHTML = myString;
}
Upvotes: 0
Views: 1694
Reputation: 8201
Alright, the problem is the inline onClick
handler on your button. Just move that to your script.js onLoad
handler and it should start to work. First add an id
to the button to make this easy.
<input id="button" type="button" value="fix" />
Next, get that button and add the onclick
function myOnload(){
var myString = document.getElementById("txtarea").innerHTML = "";
var button = document.getElementById("button");
button.onclick= function(){myClick()};
}
...
Here is a fiddle for it: http://jsfiddle.net/x2w2p/1/
Upvotes: 1