1

I am trying to append an iframe page to the page that user visits with a chrome extension. The iframe will be placed at the top of the page for example. I have succesfully managed to append the iframe with the following code (myscript.js):

var iframe = document.createElement("iframe");
iframe.src = chrome.extension.getURL("./myIframe.html");
document.body.insertBefore(iframe, document.body.firstChild);

Howevery, in my iframe page I am using a couple of javascripts (.js) that also require jquery (.js) lib. It seems that none of the scripts work making in this way the iframe page non-functional. In my content_scripts I include the lib:

 "content_scripts": [
{
  "matches" : ["http://*/*", "https://*/*"],
  "js": ["jquery.js", "myscript.js"],
  "all_frames" : true
}

],

I have also tried to include every (.js) file that the iframe uses but still didn't work. What I m actually trying to do is through an interface let the user to perform some actions on the page that sees like changing background colour. I m suspecting that performing some actions through iframe page's javascripts on the current page of user is not possible. Does anyone know what I need to do in order to fix this problem or if there is any other way to achieve what I m trying here? Thanks.

svatsi
  • 31
  • 1
  • 8
  • Read about [Extension code vs Content script vs Injected script](http://stackoverflow.com/a/9916089/938089?chrome-extension-auto-run-a-function). Also, did you specify manifest version two? – Rob W Jun 27 '12 at 07:26
  • Hi, no I didn't specify manifest version two, what is about? I don't get much understanding of the link you provided to me. Let me give you an example of what is the situation here. I have for example an image faded out and hovering on a text the image should be appear. I can see that when the iframe is loaded in the current page of user, the image is HIDDEN, meaning that jquery and javascripts work. However when hovering on text the image is not fading in. While I can see that the cursor changes to hand pointer, the jquery function seems not to be called. – svatsi Jun 27 '12 at 12:27
  • Sorry, your question lacks details. It cannot be answered without any more code. As for manifest version, when you have specified manifest version 2, some restrictions are added to your extension's code. For more details, see http://code.google.com/chrome/extensions/contentSecurityPolicy.html. – Rob W Jun 27 '12 at 12:36
  • Hi Rob, you may be right. It's about security policies. I am new in this area of development and do not know much about it. Is there any other way to add my interface in the current page of the user instead of using iframe? – svatsi Jun 27 '12 at 14:54
  • What's the purpose of your extension? Can you add any *relevant* code to the question? – Rob W Jun 27 '12 at 14:57
  • imagine some small icons for example when clicking on them to perform some actions on the elements of the web page, like changing background colour, changing the size of some texts etc. I know how to do these stuff, I just want the interface to be functional as it should be, the icons to be clickable and do what they suppose to do. – svatsi Jun 27 '12 at 15:01

0 Answers0