【发布时间】:2020-12-16 04:56:23
【问题描述】:
如何在 iframe javascript 代码中获取 iframe 属性
<div>
<iframe src="http://192.168.0.108:8092/"
name="otherDomain"
width="100%"
height="600px"
style="border: 0;"
data-auth-token="xyz"
data-auth-key="abc"
>
</div>
我正在尝试
console.log(window.frameElement.getAttribute('data-auth-token'))
如果 iframe url 和浏览器用户相同,我可以获取 iframe 属性。如果网址不同,我会收到以下错误。
Uncaught SecurityError: Failed to read the 'frame' property from 'Window': Blocked a frame with origin "http://192.168.0.108:8092" from accessing a frame with origin "http://localhost:8092". Protocols, domains, and ports must match.
是否可以在 JavaScript 中获取跨域 iframe 属性。
【问题讨论】:
标签: javascript jquery html angularjs