1.防止网页被嵌入框架
<script type="text/javascript">
try{
top.location.hostname; // 跨域报错,IE,火狐有效
if (top.location.hostname != window.location.hostname) { // 对chrome的判断
top.location.href =window.location.href;
}
}
catch(e){
top.location.href = window.location.href; // 从定位
}
</script>
本文介绍了一种通过JavaScript实现的防止网页被恶意嵌入到其他网站框架中的技术方案。该方法能够有效地检测并阻止跨域嵌套,确保网站源链接的独立性和安全性。

被折叠的 条评论
为什么被折叠?



