Currently, many webmasters prefer to use iframe to directly call others' websites. On the surface, it is impossible to see that the website calls others, and all the open views access our servers, however, the viewer thinks this is the other party's network. Next I will introduce several methods to prevent the website from being called by other people's frame.
Add the following code to your WordPress topic's functions. php:
The Code is as follows: |
Copy code |
// Break Out of Frames for WordPress Function break_out_of_frames (){ If (! Is_preview ()){ Echo "n <script type =" text/javascript "> "; Echo "n <! --"; Echo "nif (parent. frames. length> 0) {parent. location. href = location. href ;}"; Echo "n --> "; Echo "n </script> nn "; } } Add_action ('wp _ head', 'break _ out_of_frames '); |
There are two other js types to prevent code
1. Place this code between the head
The Code is as follows: |
Copy code |
<Script language = JAVASCRIPT> If (top. location! = Self. location ){ Top. location = self. location; } </SCRIPT>
|
2. This method is better. Once someone else finds that the iframe Of Your webpage has been accessed, it will automatically jump to your website.
Place the following code between the head
The Code is as follows: |
Copy code |
<Script language = JAVASCRIPT> Var url = window. location. href; If (window! = Parent) Parent. navigate (url ); </SCRIPT> |