I am working on a Chrome App, and I need the background script to access elements of an html window that it creates.
Please do not answer that I can do it from other scripts launched by the created window, because this is not what I need.
This is my background.js file:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html',
{'outerBounds': {'width': 600, 'height': 500 }},
function(myWin) {
myWin.contentWindow.document.getElementById('areaId').value='New text!';
});
});
and this is windows.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<textarea id="areaId" name="areaId" rows="4" cols="50">
This is my text.
</textarea>
</body>
</html>
When I launch the app, I get the error:
"Uncaught TypeError: Cannot set property 'value' of null"
I also tried with myWin.document.getElementById(...)
and opening the window with var myWin=window.open(...)
but without success.
So my question is, how can I access elements of the newly created window from the background script?
myWin.contentWindow.documentshould be correct. You should edit your question with that and tell what isn't working and how it isn't working.