I know that there's a few different questions like this one, but I've encountered some problems trying to implement their solutions.
I have 2 html
pages. The first one has an iframe
that contains the second page. I want the first page to be able to get the value of a textarea from the second page via the iframe
.
Here comes the problem. Both files are in the same directory on my computer but I get this error: Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
JavaScript:
window.onload = function(){
var f = document.getElementById("text-box-iframe").contentWindow;
var innerDoc = f.contentDocument || f.contentWindow.document;
}
HTML:
<iframe id="text-box-iframe" src="text-box.html"></iframe>
So here's the two questions I have: Why isn't this code able to access the iframe
's page (page 2), and what do I have to do to fix that?
IDK if this helps, but here's the second page's code:
<textarea id="text-box"></texarea>
Please don't suggest any plugins or libraries. I would like this answer in JavaScript/HTML (no jQuery), and I don't want to use postMessage
to communicate between pages. I'm almost 100% sure that this method will work, I just need some help getting it to work.
Thanks in advance.