需要在加载外部域的iframe上运行javascripts [英] need to run javascripts on iframe which loads an external domain
问题描述
mysite.com
有一个iframe,载入一些 differentsite.com。
mysite.com
has an iframe which loads some differentsite.com.
需要对此已加载的iframe文档运行javascript。
need to run javascript on this loaded iframe document.
单原始政策
。
我诉诸使用代理。
替代方案?
推荐答案
您可以尝试 window.postMessage(message,origin)
( parent.postMessage
来自iframe和
iframeElement.contentWindow.postMessage
从顶部页面)为所有最新的主要浏览器(Firefox,IE,Safari,Chrome等)。 )和为旧浏览器更改/轮询 window.name
。
You could try window.postMessage(message, origin)
(it would be parent.postMessage
from the iframe and iframeElement.contentWindow.postMessage
from the top page) for all of the latest major browsers (Firefox, IE, Safari, Chrome, etc.) and changing/polling window.name
for old browsers.
这篇关于需要在加载外部域的iframe上运行javascripts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!