What is the general purpose of top! = self?

<script language="javascript">
    if(top !== self){
        top.location.href = location.href;
    }
</script>

in some pages, I often see this, js writing. For example, the member login interface. I don"t quite understand. Why do you write it like this? what"s the use?

if the top-level (top) is not its own (self), then redirect to the url? in the address bar I don"t think it"s right when I explain it this way. Who can explain it in a more popular way?

Don"t report me. I"m a rookie. Can"t I ask a rookie question?

Apr.05,2021

there is something called iframe


to prevent people from embedding your site into their pages and doing little tricks.


this is mainly used to prevent references by iframe.
reference: what's the difference between top.location.href and localtion.href
https://www.cnblogs.com/hlws/.

Menu