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.