You can access a frame or iframe using the following syntax
Code:
var frame = window.frames["name_of_frame"];
You can easily add elements to the frames DOM using the frame reference above:
Code:
var p = frame.document.createElement("p");
p.innerHTML = "tada!";
frame.document.body.appendChild(p);
Note above that the node was created using the frame reference, since you can not append a node that was created in one document to another document.
Firefox will throw the following error if you omit the bold part above:
Code:
Error: uncaught exception: [Exception... "Node cannot be used in a document other than the one in which it was created" code: "4" nsresult: "0x80530004 (NS_ERROR_DOM_WRONG_DOCUMENT_ERR)"]
One last thing, you need to make sure that the frame content is loaded before you start adding elements to it.
Bookmarks