有人使用iframe在不同的域中使用/显示我的整个网站吗?我想在加载域名时重定向到我的页面?该怎么办?
答案 0 :(得分:1)
在页面的<head>
添加一个小脚本,以更改父级的window.location.href
<script>
if (window.parent != this) { // in the global scope this === window.
// if the window isn't the same as the parent
// change the parent's location to ours.
window.parent.location.href = window.location.href;
}
</script>
这适用于FF24和Chrome 29.您必须自己进行兼容性测试。
答案 1 :(得分:0)
您可以向网站添加标题,以便不会跨域加载。
可替换地:
<meta http-equiv="X-FRAME-OPTIONS" content="SAMEORIGIN" />
这将允许iframing在同一个域中,但拒绝在不同的域中。
答案 2 :(得分:0)
<?php session_start();
ob_start();
?>
<?php if(!isset($_SESSION['redirect'])) : $_SESSION['redirect'] = 0; endif; ?>
<script type="text/javascript">
var referrer = document.referrer;
if(referrer==''){}
else{<?php
$_SESSION['redirect']++;
if($_SESSION['redirect'] ==1): ?>window.top.location.replace("http://domain.com");<?php endif; ?>}
</script>