on chrome extension, im trying to add a an iframe on all websites,
currently my manifesjt.json
{
"name": "Testinjection",
"version": "1.0.0",
"manifest_version": 2,
"description": "Testinjection",
"icons": {
"48" : "sample-48.png",
"128" : "sample-128.png"
},
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*" ],
"js" : ["contentscript.js"]
}
]
}
and contentscript.js:
document.write("<iframe src=\"http:\/\/www.ask.com\" width=\"100%\" height=\"40px\"><\/iframe>");
The problem is that this code is replacing the current visited page and not adding this code to top,
in which way can i do this?
Using
document.writeafter your page has loaded will overwrite the page. You should construct an element instead:Demo: http://jsfiddle.net/XrqvG/