使用框架杀手.
CSS:
<style>
html{display:none;}
</style>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
<script>
function frameKiller() {
if (self == top) {
document.documentElement.style.display = 'block';
} else {
top.location = self.location;
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
然后在要保护的页面上调用framekiller功能
jQuery的:
$(function () {
frameKiller();
});
Run Code Online (Sandbox Code Playgroud)
完整示例:
<!DOCTYPE html>
<head>
<title>Page Title</title>
<style>
html{display:none;}
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
Page Content
<script>
function frameKiller() {
if (self == top) {
document.documentElement.style.display = 'block';
} else {
top.location = self.location;
}
}
$(function () {
frameKiller();
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
要进行测试,请尝试将此页面加载到来自其他域的iframe中.
归档时间: |
|
查看次数: |
415 次 |
最近记录: |