Method to prevent a page from being called by an iframe
- 2020-03-30 04:13:02
- OfStack
This article illustrates how js prevents a page from being called by an iframe. Share with you for your reference. The specific implementation method is as follows:
I. problem description:
Sometimes we find our website page is called by someone else and exactly the same, this is actually a simple iframe call, next I will give you js to prevent the page iframe call method summary, there is a need for friends to refer to
Ii. Solutions:
Prevent your web pages from being framed:
Top.location.href the address at the top
Windows.location.href's own address
Self refers to the current window object, the object at the top of the window;
Location.href refers to the URL address of a window object.
Self.location.href refers to the URL address of the current window
<script type="text/javascript">
if(top.location != self.location){
top.location = self.location;//Prevents pages from being included in the frame & NBSP; < br / >
}
</script>
These methods are feasible, but not very reliable.
<script language="javascript">
if( top.location != self.location) top.location.href=self.location.href;
</script>
or
<script language="javascript">
if (top.location != location) top.location.href = location.href;
</script>
or
<script language="javascript">
if (top.location != self.location) {top.location=self.location;}
</script>
or
<script language="javascript">
if (top.frames.length!=0) top.location=self.document.location;
</script>