1. How to determine whether it is in an iframe
Js code
//Method Oneif ( && == "IFRAME") { alert('In iframe'); } //Method 2if ( != ) { alert('In iframe'); } //Method Threeif (self != top) { alert('In iframe'); }
2. Prevent web pages from being nested by other sites using iframes
Add the following code to your page <head></head> location:
Js code
<script language="javascript"> <!-- if ( != location) { = ; } //--> </script> //or<script language="javascript"> if(self!=top){=;} </script>
This will prevent others from using iframes to nest any page of your website. The effect is: after entering the address of your website that steals the link, it will automatically jump to your website.
Reasons for unreliability:
When others use similar codes to make IFRAME nested calls, they may avoid the javascript code of your page.
Js code
<iframe src="Your page address" name="tv" marginwidth="0" marginheight="0" scrolling="No" noResize frameborder="0" framespacing="0" width="580" height="550" VSPACE=-145 HSPACE=-385></iframe> <script language="javascript"> var location=""; var navigate=""; frames[0].=""; </script>
2. The most reliable method:
In order to completely prevent others from using the IFRAME framework to call their own web pages, the following method is the most reliable.
Here the value is assigned to an empty page, or the URL address of your page can be assigned to it.
Js code
<script language="javascript"> if(top != self){ = "about:blank"; } </script>
Another way to completely block the iframe is to add:
Html code
header("X-Frame-Options: deny"); header("X-XSS-Protection: 0");
This is also loading an iframe that generates an error"Load denied by X-Frame-Options: http://localhost/××××.php does not permit framing.” Reason!
The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!