iframe cross-domain problem
P粉939473759
2023-08-24 09:35:29
<p>Suppose I have a website called example.com with an iframe embedded in the iframe.net domain, now I want to read the content of the iframe and pass some parameters to display a text message. Like to use the username Hi. </p>
<p>Now the problem is that this cannot establish a connection between the two or even get the innerHTML of the iframe which I use below</p>
<pre class="brush:php;toolbar:false;">document.getElementById('myframe').contentWindow.document.body.innerHTML;</pre>
<p>It throws the error "Permission to access property is denied"</p>
<p>Does anyone know how to read and write across cross-domain platforms</p>
In Internet Explorer 8, events passed as parameters may be null, which is why you need to access the events differently:
In frame.html:
On main.html:
The event is triggered the same way as presented by Rob W:
If you have no control over the website being framed, there is no way to circumvent the cross-origin policy.
If you have control over both sites, you can use the
postMessage
method of transferring data across domains. A very basic example: