Why is my iframe blocked by cross origin even it is not


Why is my iframe blocked by cross origin even it is not



I have a <iframe> inside a <div>. My outer url is http://localhost:9090 and the src in iframe is http://localhost:9090/Server/v1. In my outer context I have below code to access iframe dom:


<iframe>


<div>


http://localhost:9090


http://localhost:9090/Server/v1


const f1 = window.frames[iframeName];
const iFrameHead = f1.document.getElementsByTagName("head")[0];



and I get an exception on the second line:



Uncaught DOMException: Blocked a frame with origin
"http://localhost:9090" from accessing a cross-origin frame.



The reason I want to access ifame dom is that I need to insert a script into that iframe. The src in iframe has the same protocol, hostname and port number. What I don't understand is the iframe is on the same origin as the parent context. Why does it complain about the cross origin?



After some debugging, I found there is because the iframe was redirected to a different domain than its src. I wonder whether there is a workaround to insert a script into this iframe?


iframe


src





different port, try to make a ssh tunnel. ssh.com/ssh/tunneling/example
– Santiago Rebella
Jun 30 at 0:37






both use 9090 as the port number. Why do you say it is a different port?
– Zhao Yi
Jun 30 at 0:44





just a shot in the air, need more info whats going on, thats tipically that error msg
– Santiago Rebella
Jun 30 at 0:54





which error msg said about different port?
– Zhao Yi
Jun 30 at 0:56





are you in https?
– Santiago Rebella
Jun 30 at 1:02









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV