I am currently trying to create a chrome extension that alters a website (an interface for a ip camera that I bought, thats also why the site is a local site like 192.168.178.70 for example). I just want to add some buttons and stuff like that to add some functionality.
I used
document.body.onload
to wait until everything has loaded so I can grab a table or a div or whatever and create and add my button to it. But document.getElementById("ipcam_wrapper") does not seem to work properly, it returns null.
Well I tried to do the same thing in google chrome developer mode but it does also return null. I actually managed to get the element this way once but I am not able to recreate it because I did not do anything different.
There is only one element with that specific ID.
Here i try to get the element:
So what am I doing wrong?
best regards
2 Answers 2
Thanks to Nisarg Shah, I was able to resolve my issue. Thank you very much for your help!
The issue was that the element I was trying to access was inside an iframe. Also thank you RaYell for providing the necessary code, with which I was able to resolve my problem:
window.frames['mainframe'].document.getElementById('example')
1 Comment
window.frames['mainframe']?I think it's because the document itself won't be loaded yet.
I fixed it by using window.onload instead of document.body.onload, like:
window.addEventListener("load", ev => {
// it should work
document.getElementById("ipcam_wrapper")
});
Comments
Explore related questions
See similar questions with these tags.
document.getElementById. See section "Selecting Execution Context" in this article: developers.google.com/web/tools/chrome-devtools/console