could someone help me to understand why this errors
document.getElementById("actContentToGet").contentWindow.document.body.getElementById is not a function
function deleteElement(element){
var elementID = $(element).attr("class");
alert(elementID);
document.getElementById('actContentToGet').contentWindow.document.body.getElementById(elementID).remove;
alterContent();
giveAllIDs();
hoverLoad();
}
contents() can get both text nodes and HTML elements. That's why one can get document contents of an iframe by using it. Note that the iframe and page have to be on the same domain.
It is called an inline frame because to the user it is all one web page. The child iframe is a complete browsing environment within the parent frame. It can load its own JavaScript and CSS separate from the parent.
To get the element in an iframe, first we need access the <iframe> element inside the JavaScript using the document. getElementById() method by passing iframe id as an argument. const iframe = document.
You can read the contents in an iframe easily via jQuery ( $(iframe). contents() ) if the domain of the webpage which contains the iframe is same as the domain of the web-page opened in iframe . The microservice responsible for uploading file was on different domain and the main app is on another domain.
Try changing this:
...contentWindow.document.body.getElementById(elementID)...
to this:
...contentWindow.document.getElementById(elementID)...
Edit from comments: It's not removing that element because that's not how you remove elements. Try this:
var iframe = document.getElementById('actContentToGet');
var frameDoc = iframe.contentDocument || iframe.contentWindow.document;
var el = frameDoc.getElementById(elementID);
el.parentNode.removeChild(el);
See the documentation here.
Try removing the body.
- getElementById() is a document.
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With