leer el contenido de iframe de la extensión de Chrome

I'm trying to load iframe.html inside an iframe and append that iframe to the DOM of the current page from my chrome extension. I have done so and I am able to handle click events, get the frame element values(input,select box). Everything is fine till here. Now the problem is I couldn't modify the content inside the iframe.html once I have inserted it into the DOM(To be more specific, I have a input box in iframe.html[which is appended to the DOM] with value as "XXXX" and now I want to change it to "YYYY" when user clicks on context menu of my extension).

I tried to get the input box value by using

$('#iframe_id').contents().find('input#input_id').val('YYYY')
(or)
window.frames['iframe_id'].document.getElementId('input_id').value

in my content.js but of no help.

console.log($('#iframe_id'))

prints the iframe Object in the console but unable to get the iframe document content. Is this the right way to get/modify the iframe content inserted by a chrome extension? or am I missing something here from chrome.* APIs

Any pointers on how to resolve this would be more helpful.

TIA, Jagadeesh

preguntado el 24 de agosto de 12 a las 19:08

Why use an iframe? It seems to complicate your solution based on te given information. -

What would you suggest me to do? Some pointers on this -

What is the content that you are trying to pull in the iframe? Maybe you can get the data in another way. Dealing with iframes is always a pain. -

I have some input fields. I need to read the values and modify it when user clicks on context menu of my extension. -

Yes. You'll have to do a little bit more work to get the styling to work how you want but I believe it to be the better approach in the long run. -

2 Respuestas

I believe you are having problems because the domains and protocols of the iframe and top-level page don't match. This is a page security restriction. If this does describe your problem you can workaround the restriction by using the iframe postMessage API.

Respondido 26 ago 12, 00:08

I don't think this should be a problem with chrome extensions as I already have taken cross-origin permissions in manifest.json file. More here desarrollador.chrome.com/extensions/xhr.html - jagadeesh

As Mike Grace mentioned, I have inserted html instead of iframe and constructed the css such that it would work in any of the web pages. This would be a better approach in the long run.

Respondido el 21 de enero de 13 a las 18:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.