I can't find the related question where I found this link but here is a paper about FrameBusting and how you should implement it.
Written by Gustav Rydstedt, Elie Bursztein and Dan Boneh from the Stanford University with the collaboration of Collin Jackson of the Carnegie Mellon University
This is the paper recommandation :
<style>
body {display: none; }
</style>
<script>
if (self === top) {
document.getElementsByTagName("body")[0].style.display = 'block';
} else {
top.location = self.location
}
</script>
Notice the display: none
, this is super important, because attacker can just disable javascript on part of your page. See the paper for more informations.