+
82
-

如何判断网页是否在inframe内打开?

今天发现别人到我的页面,请问如何通过js来检测我的网页在别人的iframe中呢?

网友回复

+
1
-

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>

    <script type="text/javascript">

        //判断是否在iframe中
        if (self != top) {
            alert("在iframe中打开");
            //下面的代码可以强制将iframe父页面地址换成iframe地址,防止别人用iframe打开自己的页面
            //parent.window.location.replace(window.location.href);
        }

    </script>
</head>
<body>

</body>
</html>

我知道答案,我要回答