Home  >  Article  >  Web Front-end  >  How to block and prevent other websites from embedding frame code_javascript skills

How to block and prevent other websites from embedding frame code_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:43:311496browse

Is your webpage being used by others? There are currently some aggregation websites that, after adding their own advertisements and LOGOs at the top or bottom, begin to arbitrarily crawl the content of other sites, claiming to provide essential information; there are also some sites that are Adding a frame causes traffic to be brushed.

Although being used by others in this way can increase your own traffic, uninformed readers will think it is the content of his site, leading to the loss of users.

The following will introduce you through several methods how to block and prevent other websites from embedding frame codes.

Method 1:

<SCRIPT LANGUAGE=javascript> 
if (top.location != self.location)top.location=self.location;
</SCRIPT>

Instructions:

top.location refers to the url of the parent page to which the current page belongs

self.location refers to the url of the current page

if (top.location != self.location) The parent window url is different from the current url, indicating that it is embedded

top.location=self.location; Set the URL of the embedded form to be the same as this form

Method 2:

What to do if your webpage is added to a frame? There are two methods below.

Between the heads, add the following JS code:

How to prevent web pages from being embedded with frame code. In order to make it easier to copy the Javascript code, the code is listed below:

<script language=javascript>
<!--
if (top.location != self.location)top.location=self.location;
//
-->
</script>

Why can the above Javascript code automatically jump to the outermost frame? It is mainly to detect whether the webpage is at the top when it is opened. If it is wrapped in a frame, it will break away from the frame.

The second method is also to put the head.

<script type="text/javascript">
if (window!=top) // 判断当前的window对象是否是top对象
top.location.href =window.location.href; // 如果不是,将top对象的网址自动导向被嵌入网页的网址
</script>

This way, no one can embed your page, but this way, you can't use it either.

Write at the end:

Nowadays, there are fewer and fewer methods of using frames, but we still have to be cautious. Lu Songsong’s blog was previously flooded because it was framed.

With the popularity of social commenting, sharing and other plug-ins in recent years, the situation of "actively sending content" to other websites has become more and more obvious.

The above introduction is the detailed description of how to block and prevent other websites from embedding frame code. I hope it will be helpful to everyone.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn