如果将网站加载到 iframe 中,我需要在该 iFrame 的子页面上放置什么代码才能脱离 iFrame 并将该页面加载为顶部文档或重定向到该页面
刚刚找到代码
<script>
if(window.top !== window.self){
window.top.location.href = "http://www.blah.com";
}
</script>
更好的代码:
<style> html{display : none ; } </style>
<script>
if( self == top ) {
document.documentElement.style.display = 'block' ;
} else {
top.location = self.location ;
}
</script>
下面的代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
blah
</head>
<body>
<iframe src="www.blah.com"></iframe>
</body>
</html>
我需要在(在本例中)www.blah.com 上放置什么 JQuery 或 javascript,以便它脱离 iframe 并直接向用户显示 www.blah.com?