在我的场景中,我在页面的iframe部分有一个按钮,用于执行一些数据库处理。
当我按下iframe中的这个按钮时,我基本上需要的是执行主页面页面刷新的方法。
非常感谢我可以在iframe中触发的javascript,它将重新加载包含iframe的主窗口。
感谢。 贝。
答案 0 :(得分:108)
window.top.location.reload();
答案 1 :(得分:11)
如果父级和子级iframe域名不同,则会出现跨窗口安全性错误,在这种情况下,您可以尝试使用以下内容:
window.parent.location = document.referrer;
答案 2 :(得分:8)
window.parent.location.reload();
答案 3 :(得分:2)
我们可以通过设置target =" _parent"轻松实现面对目标。到iframe里面的链接。
就像下面的演示一样:
<!--ParentPage.htm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
Parent Page
<iframe src="FramePage.htm"></iframe>
</body>
</html>
<!--FramePage.htm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="http://www.g.cn" target="_parent">hello</a>
</body>
</html>
答案 4 :(得分:0)
在您的顶部框架上定义allFrame变量:
var allFrame=1
并在所有框架上检查此功能
if(top.allFrame === undefined)
{
window.parent.location = "your website top frame";
}
答案 5 :(得分:0)
window.opener.top.location.reload();
答案 6 :(得分:0)
如果您使用aspx C#对Page进行编码,则可以查看代码:
console.log(pathJoin(['https://', 'hostname', 'path/'])); // 'https://hostname/path/'
console.log(pathJoin(['relative/', 'path', 'to/dir/'])); // 'relative/path/to/dir/'
console.log(pathJoin(['/absolute/', 'path', 'to/file'])); // '/absolute/path/to/file'