这是我的测试页。在此页面上有一个 iFrame,其中嵌入了我网站的另一个页面。
<html>
<head>
<title>Clickjack test page</title>
</head>
<body>
<p>Website is not vulnerable to clickjacking.</p>
<iframe src="admin.html" width="500" height="500" id="iframe"></iframe>
</body>
</html>
这是我正在使用的 JavaScript。这段代码在 admin.html
<script type="text/javascript">
if(window.location != window.parent.location){
// is within an iframe
/* $("iframe").bind('load', function(){
$("iframe").contents().find("body").css('display', 'none');
$(this).hide();
}); */
}
else {
// not within an iframe
}
</script>
这里的目标:
当您访问 ClickJacking 测试页面时,应将 iframe 中的 html 设置为 display: none。
我不希望任何人能够看到 iframe 中的管理页面。
如您所见,我有几次注释掉的尝试。但无论我做什么,admin.html 仍然可见。
任何帮助表示赞赏!