1
I own a site on a certain domain and within that site an Iframe with different port domain and host, but within this Iframe I want to realize a "document.getElementsByClassName('classe')[0].innerText"
of a class outside of Iframe, but the error:
"VM2184:1 Uncaught Typeerror: Cannot read Property 'innerText' of Undefined at :1:131"
I believe it is because I am trying to read a data from outside Iframe, I researched several ways to solve but so far I have not found an answer to answer.
Code:
$(document).ready(function teste() {
var dados = window.document.getElementsByClassName('classe')[0].innerText
if (dados != null) {
document.getElementById('nome').value = dados;
$.post("/WebAPI/api/funcao", { data: dados });
reset();
}
});
Is there a reverse path too? type i’m in Iframe running a code to grab an element from the main page?
– jonathanOliveira
Unlike no! It would be very unsafe! Imagine you put a script on your page that screws with the index of who put the iframe on it!
– John Olsen
makes sense kk, thank you very much clarified things here!
– jonathanOliveira
If I could answer accurately, could I mark it as correct? = D
– John Olsen