Error trying to access a iframe in JavaScript

旧街凉风 提交于 2019-12-03 15:22:46

When accessing an iframe with JavaScript or making any JSON AJAX requests, you can only get access or a response when they are on the same domain. Otherwise, the server must explicitly set:

Access-Control-Allow-Origin: *

in the headers. You can also provide a comma-separated list of allowed domains instead of *.

So you must test this in a development environment where the web page and data source are on the same domain, such as localhost, otherwise there isn't really anything else you can do unless you start-up chrome with --disable-web-security

You could add this to your iframe

sandbox="allow-same-origin allow-scripts"

not supported in opera though - new item from w3schools. It will take care of the error, but it will break the player.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!