javascript 使用不同的域从自身内部刷新 iframe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17296585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
refresh iframe from inside itself with different domains
提问by Dustin Silk
i have a webpage which is housing my iFrame which is from a different domain. Now i have a button inside the iFrame which when pressed, needs to refresh or reload the iframe.
我有一个网页,其中包含来自不同域的 iFrame。现在我在 iFrame 中有一个按钮,按下时需要刷新或重新加载 iframe。
I've tried a few methods which are blocked due to cross domain attempts..
我尝试了一些由于跨域尝试而被阻止的方法。
回答by Rob Hardy
In your script within the iframe, try this:
在 iframe 中的脚本中,试试这个:
document.location.href = document.location.href;
You can't access elements outside of your document model from within the iframe, including accessing the iframe itself. You can access the properties of the document within it however.
您无法从 iframe 内部访问文档模型之外的元素,包括访问 iframe 本身。但是,您可以访问其中的文档属性。