Console displays Uncaught SecurityError

2019-03-03 23:34发布

问题:

I'm not sure how I can fix the error below. Can somebody help me out?

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://mysite.net" from accessing a frame with origin "https://www.youtube.com". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.

回答1:

You are trying to access an https url from within a http website. HTTPS and HTTP are different protocol and is causing a mismatch.

I think the following link might help: https://productforums.google.com/forum/#!topic/chrome/ODpydGiCgiE

if you want to access frames in a iframe you can change top with 
parent.frames only for accessing frames in the iframe who execute javascript.
try to change top with parent.frames

return top.frames;

return parent.frames;

in google chrome it work for me i can access all my frames in my iframe.

Or if you are just trying to access your own domain with different protocol, you can also try setting the Access-Control-Allow-Origin header.

How does Access-Control-Allow-Origin header work?



回答2:

Try using // instead of specifying the protocol with http:// or https:// in the iFrame URL address source address. It should use the protocol of the site.