This article example describes how js prevents pages from being called by iframes. Share it for your reference. The specific implementation method is as follows:
1. Problem description:
Sometimes we find that our website page is called by others and is exactly the same. This is actually a simple iframe call. Let me introduce to you the method of preventing iframe calls on the js page. Friends who need it can refer to it.
2. Solution:
Prevent your web page from being framed:
top.location.href
windows.location.href's own address
self refers to the current window object, which belongs to the uppermost layer of window;
location.href refers to the URL address of a certain window object.
self.location.href refers to the URL address of the current window. Remove the URL address of the default self to the current window.
Copy the code as follows:<script type="text/javascript">
if(top.location != self.location){
top.location = self.location;//Prevent the page from being included by the framework
}
</script>
These methods are possible, but not very reliable.
Copy the code as follows:<script language="javascript">
if( top.location != self.location) top.location.href=self.location.href;
</script>
or
Copy the code as follows:<script language="javascript">
if (top.location != location) top.location.href = location.href;
</script>
or
Copy the code as follows:<script language="javascript">
if (top.location != self.location) {top.location=self.location;}
</script>
or
Copy the code as follows:<script language="javascript">
if (top.frames.length!=0) top.location=self.document.location;
</script>
I hope this article will be helpful to everyone's JavaScript programming.