Prevent websites from being referenced by others through the iframe framework

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.