Prevent page from being IFRAME (compatible with Ie,firefox Firefox) _javascript tips

Source: Internet
Author: User
This code was previously used to prevent the page from using the IFRAME
Copy Code code as follows:

<script type= "text/javascript>
if (top.location!== self.location) {
Top.location=self.location;
}
</script>

But in Firefox you will find that the page will be constantly in the brush. The page doesn't work at all.
Here is because the Firefox windows.top if not so is empty, under IE windows.top is this window page constantly refresh the running of this section of JS code This creates a dead loop, is why the page has been refreshed.

So I changed the way that the following code is compatible with Firefox
Copy Code code as follows:

<script type= "text/javascript>
if (window!=parent)
Parent.navigate (WINDOW.LOCATION.HREF);
</script>

That will solve the problem.
PHP is also useful to implement
Copy Code code as follows:

<?php
$url = $_server[' http_host '];
if ($url!= ' www.jb51.net ')
{
Exit ();
}
?>


ASP Implementation Code
Copy Code code as follows:

Yuming=request.servervariables ("SERVER_NAME")
If yuming<> "Www.jb51.net" Then
Response.Redirect "Http://www.jb51.net"
End If


Other languages have similar principles, and you can get the environment variables to get them.


I hope we can help you here.

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.