What should I do if the web page is iframed?

小云云
Release: 2017-11-18 09:41:00
Original
2581 people have browsed it

Everyone knows that there is a function called "nesting", but the website you have worked so hard to build is used by someone else to use an iframe to put a vest on you and it becomes the content of his page. Maybe you will be very angry and want to stop it. , so what should you do to avoid preventing web pages from being iframed? Here are several methods to teach you how to prevent your website and web pages from being iframed by others.

(1) The first way to prevent the page from being iframed, add the following JS code to the page:

Copy after login

(2) The second way to prevent the page from being iframed, add the following to the page JS code:

Copy after login

It is said that this solution will keep refreshing the page under Firefox. This is because windows.top is the current window under IE, and if there is no windows.top under Firefox, then it is null. Therefore, this js code will be continuously run, which creates an infinite loop and causes the page to be refreshed all the time.

(3) The third way to prevent the page from being iframed is to add the following JS code to the page:

Copy after login

In addition, if you use a web program developed with php, you can also use php directly to implement it. To prevent a page from being iframed, add the following to the program code:

 if($_server['http_host']!='www.phpernote.com'){    
 exit('禁止iframe我的页面!囧');    
}
Copy after login

The asp language also has its own unique implementation code for prohibiting a page from being iframed, as follows:

host=Request.ServerVariables("SERVER_NAME")    
if host<>"www.phpernote.com" then    
response.redirect "http://www.phpernote.com/"    
end if
Copy after login

Of course, other programming languages ​​can also be used. The effect of preventing the page from being iframed is achieved by obtaining environment variables. I will not give examples one by one here.

When you want to prevent others from iframe your website or webpage, you might as well try the above method, I hope it can help you.

Related recommendations:

How to use the iframe attribute

A case study on how to asynchronously upload an iframe in a php form file

How to prevent web pages from being nested in iframes?

The above is the detailed content of What should I do if the web page is iframed?. For more information, please follow other related articles on the PHP Chinese website!

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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!