JavaScript implements code sharing to prevent web pages from being embedded into the Frame framework. javascriptframe

Source: Internet
Author: User

JavaScript implements code sharing to prevent web pages from being embedded into the Frame framework. javascriptframe

Recently, another kind of rogue behavior has become popular in China: Using Frame to embed your webpage into its webpage.
For example, a website claims to be a "word-of-mouth aggregation Portal" to provide the best content of various online forums across the country. However, in fact, it is to use a framework to capture others' web pages and add its own advertisements and site labels on the pages. What is the difference between this and the copybook piracy ?!

Protection method, in

Copy codeThe Code is as follows:
</Body>

Add this code before:


Copy codeThe Code is as follows:
<Script type = "text/javascript">
If (top. location! = Self. location)
{
Top. location = self. location;
}
</Script>


This code is valid. However, there is a problem: once used, no one can embed your webpage into the framework, including yourself.

Is there a way for my webpage to be embedded in my own framework rather than other frameworks?

Copy codeThe Code is as follows:
<Script type = "text/javascript">
Try {
Top. location. hostname;
If (top. location. hostname! = Window. location. hostname ){
Top. location. href = window. location. href;
}
}
Catch (e ){
Top. location. href = window. location. href;
}
</Script>

Now, the upgraded code is complete. All domain names except the local domain name cannot embed your webpage into the framework. My Blog now uses this code.

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.