JS prevents page iframe from calling code

Source: Internet
Author: User

Prevent your own web page from being framed by people
Top.location.href the top of the address
Windows.location.href own address.

Self refers to the current Window object, which belongs to the topmost object of Windows;
Location.href refers to the URL address of a Window object.
Self.location.href refers to the URL address of the current window, removing the URL of the current window that the self defaults

The code is as follows Copy Code


<script type= "Text/javascript" >
if (top.location!= self.location) {
Top.location = self.location;//prevents the page from being contained by the frame
}
</script>

1. These methods are feasible, but not too reliable.

  code is as follows copy code

<script language= "JavaScript"
if (top.location!= self.location) top.location.href=self.location.href;
</ Script>

or

<script language= "JavaScript"
if (top.location!= location) Top.location.href = Location.href;
</script>

or

<script language= "JavaScript"
if (top.location!= self.location) {top.location=self.location;}
</script>

or

<script language= "JavaScript"
if (top.frames.length!=0) top.location=self.document.location;
</script>

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.