javascript - Getting a content script to append image on page load -


i've start out learning how make extensions google chrome. have basic understanding far, wanted try small.

right trying image append specific div on specific page everytime page loads. extension loads but, javascript code never seems run , image never gets loaded.

this manifest.json file have far:

{     "manifest_version": 2,     "name": "icon creator",     "description": "creates custom icon page",     "version": "1.0",      "content_scripts": [     {         "matches": ["file:///home/tijko/documents/learning/javascript/test_page.html"],         "css": ["sample.css"],         "js":["trial.js"]     }     ],     "icons": {"icon": "icon.jpg"},     "web_accessible_resources":["trial.js"] } 

and javascript:

var test = function() {     custom_icon = document.createelement("img");     target = document.getelementbyid("location");     custom_icon.src = "icon.png";     target.appendchild(custom_icon); } test() 

are trying load own extension's icon.png? right trying load icon.png on domain , path of local page. instead, should do:

custom_icon.src = chrome.extension.geturl("icon.png"); 

to refer extension's icon.png.

also, must list icon.png in web_accessible_resources. furthermore, don't need list trial.js in web_accessible_resources (except very specialized use cases).

finally, need approve extension access file:// pages checking appropriate box under extension's listing in chrome://extensions.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -