javascript - onClick within Chrome Extension not working -


this seems easiest thing do, it's not working. in normal browser .html , .js files works perfectly, in chrome extension onclick function not performing it's supposed do.

.js file:

function hellyeah(text) {   document.getelementbyid("text-holder").innerhtml = text; } 

.html file:

<!doctype html> <html>   <head>     <title>       getting started extension's popup     </title>     <script src="popup.js"></script>   </head>   <body>     <div id="text-holder">       ha     </div>     <br />     <a onclick=hellyeah("xxx")>       hyhy     </a>   </body> </html> 

so once user clicks "hyhy", "ha" should change "xxx". , again - works in browser not work in extension. know why? in case i'm attaching manifest.json below well.

thanks in advance!

manifest.json:

{   "name": "my first extension",   "version": "1.0",   "manifest_version": 2,   "description": "the first extension made.",   "browser_action": {     "default_icon": "icon.png",     "default_popup": "popup.html"   },   "permissions": [     "http://api.flickr.com/"   ] } 

chrome extensions don't allow have inline javascript (documentation). going have similar this.

assign id link (<a onclick=hellyeah("xxx")> becomes <a id="link">), , use addeventlistener bind event. put following in popup.js file:

document.addeventlistener('domcontentloaded', function() {     var link = document.getelementbyid('link');     // onclick's logic below:     link.addeventlistener('click', function() {         hellyeah('xxx');     }); }); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -