我有一个名为main.jsp的页面,它在域domain1中,它有一个从domain2加载内容的iframe。基本上,main.jsp是一种常见的内容,在iframe中,我们从部署在不同服务器上的其他web应用程序加载内容。
我的问题是我想自动刷新iframe中的内容(比如5秒)。我首先尝试了以下代码:
<meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />" />Err: Blocked a frame with origin "http://localhost:8080" from accessing a cross-origin frame
我试过这段代码:
<script type="text/javascript">
window.setTimeout(function(){ window.location.reload() }, 15000);
</script>这也给了我同样的错误。有人能指导我如何做到这一点吗?
注意:为了避免跨域问题,我添加了以下代码:
<script type="text/javascript">
document.domain = window.location.hostname.replace('www.', '');
</script>发布于 2013-12-09 18:09:53
尝试动态添加它
function addRefresh(){
var meta = document.createElement('meta');
meta.setAttribute("http-equiv", "refresh");
meta.setAttribute("content", "5");
document.getElementsByTagName('head')[0].appendChild(meta);
}
if(location.origin === 'domain1.com'){
addRefresh();
}https://stackoverflow.com/questions/20467595
复制相似问题