Home > Web Front-end > JS Tutorial > Prevent pages from being iframed (compatible with IE, Firefox)_javascript skills

Prevent pages from being iframed (compatible with IE, Firefox)_javascript skills

WBOY
Release: 2016-05-16 18:23:46
Original
1034 people have browsed it

Previously, this code was used to prevent pages from being used by iframes

Copy code The code is as follows:

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


But in Firefox you will find that the page will keep refreshing. The page is not usable at all.
This is because if there is no windows.top in firefox, it will be empty. In IE, windows. Top means that the page in this window is constantly refreshed and this js code is constantly running. This creates an infinite loop, which is why the page keeps refreshing.

So I changed the method and used the following code to be compatible with firefox
Copy code The code is as follows:



This problem is solved.
There is also php to implement
Copy the code The code is as follows:

$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


The principles of other languages ​​are similar, and you can obtain the environment variables.


I hope this can help everyone.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template