当 iFrame 从本地 html 文件加载本地 html 文件时,Chrome 的未来版本是否可能支持 contentWindow/contentDocument? [英] Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?

查看:30
本文介绍了当 iFrame 从本地 html 文件加载本地 html 文件时,Chrome 的未来版本是否可能支持 contentWindow/contentDocument?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Chrome 的 iFrame (frame.src=) 中让本地 html 加载另一个本地 html 文件时,我无法通过 contentWindow 或 contentDocument 访问其文档(即使验证 contentWindow 是文档本身),因为它似乎当涉及本地 html 文件时,Chrome 不允许这样做.此功能是否可能会在 Chrome 的下一版本中更改?注意:它适用于(contentDocument 或 contentWindow)与 Safari 和 Opera、IE、WebKit.这似乎是一个安全问题,但 contentDocument 和 contentWindow 来自 W3C.

When I make a local html load another local html file in a iFrame (frame.src=) in Chrome, I cannot access its document through contentWindow or contentDocument (even with the verification of contentWindow being the document itself) because it seems Chrome doesn't allow it when a local html file is involved. Is it possible that this feature will change in next releases of Chrome? Note: it works (contentDocument or contentWindow) with Safari and Opera, IE, WebKit. It seems to be a security issue but contentDocument and contentWindow are from W3C.

推荐答案

这是因为 Chrome 限制,称为同源策略.默认情况下,本地文件被认为属于不同的来源,不允许从另一个访问.要解决此问题,您可以使用 --allow-file-access-from-files 命令行开关启动 Chrome 应用程序.

It is because of Chrome restriction known as Same-Origin Policy. By default the local files are considered to belong to different origins and not allowed to access one from another. To solve the issue, you can launch the Chrome application with the --allow-file-access-from-files command-line switch.

这篇关于当 iFrame 从本地 html 文件加载本地 html 文件时,Chrome 的未来版本是否可能支持 contentWindow/contentDocument?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆