Recently, another rogue behavior has become popular in the country: use frame to embed your Web page in its Web page.
For example, there is a website claiming to be a "word of mouth aggregation portal", providing the essence of every online forum in the country. But, in fact, it is to use the framework to crawl other people's Web pages, and then add their own ads and stations, which is different from the Pirate booksellers?!
Prevent methods, in
Copy Code code as follows:
Before adding this code:
Copy Code code as follows:
<script type= "Text/javascript" >
if (top.location!== self.location)
{
Top.location = self.location;
}
</script>
This piece of code is valid. However, there is a problem: after use, no one can embed your Web page into the framework, including yourself.
Is there a way to make my web page can only be embedded in my own frame instead of someone else's frame?
Copy Code code 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>
OK, the upgrade code is complete. In addition to the local domain name, other domain names will not be able to embed your Web page frame. My blog now uses this piece of code.