Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome extension javascript function is not defined
    primarykey
    data
    text
    <p>I'm Developing an chrome extension and encountered an problem i cannot solve ;/</p> <p>I wrote the manifest file and some java script code. Everything is working good except buttons. When I click them they should fire the echo function with an parameter and send it further to a plugin developed in firebreath. When I inject code manually in a html file everything is working fine but when injecting the code through javascript chrome console gives me an message that echo function is not defined. I tried several ways to inject the code but none work. </p> <p>So I ask for help or some good advice fellow programmists. (First post <em>shy</em>)</p> <p><strong>Main javascript file chrome_script.js</strong></p> <pre><code>var Reg = /(\+48\s?[0-9]{3}[\-\ ]?[0-9]{3}[\-\ ]?[0-9]{3})|(\+48\s?[\(\ ]?[0-9]{2}[\)\ ]?[0-9]{2,3}[\-\ ]?[0-9]{2}[\-\ ]?[0-9]{2})/g var content = document.body.innerHTML; var phoneNumbers = content.match(Reg); document.getElementsByTagName('head')[0].innerHTML +='&lt;script src="'+chrome.extension.getURL("plug_fun.js")+'" type="text/javascript"&gt;&lt;/script&gt;'; content = "&lt;object id=\"plugin0\" type=\"application/x-testplugin\" width=\"100%\" height=\"300\"&gt;&lt;/object&gt;" + content; for (var i = 0; i &lt; phoneNumbers.length; i++) { content = content.replace(phoneNumbers[i], "&lt;button id=\"" + i + "\" type=\"button\" onclick=\"javascript:echo(" + phoneNumbers[i].replace(new RegExp("[\+\ ]", "g"),"") + ")\"&gt;" + phoneNumbers[i] + "&lt;/button&gt;"); } document.body.innerHTML = content; </code></pre> <p><strong>javascript file plug_fun.js, for plugin and buttons</strong></p> <pre><code>function plugin0(){ return document.getElementById('plugin0'); } plugin = plugin0; function echo(a){ var num = String(a); plugin().echo(num); } </code></pre> <p><strong>manifest file manifest.json</strong></p> <pre><code>{ "name": "Phone Injection", "version": "0.2", "browser_action": { "default_icon": "Phone.ico" }, "permissions": [ "tabs", "http://*/*", "https://*/*", "file://*" ], "plugins": [ { "path": "npTestPlugin.dll", "public": true } ], "content_scripts": [ { "matches": ["http://*/*", "https://*/*", "file://*"], "js": ["chrome_script.js", "plug_fun.js"] }] } </code></pre> <p><strong>Error caught when clicking the button</strong></p> <blockquote> <p>Uncaught ReferenceError: echo is not defined</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload