How can i stop my website from being loaded in an iframe

What html code should i insert so that a web-page refuses to connect in a iframe ???

Normally, websites don’t. They only open in an iFrame if you tell them to. You might want to check your code.

1 Like

can u please suggest me a code or script in html which i can add in my index.html

Can you send me your website URL?

The function to control whether other websites can embed your page in an iframe is not based on HTML code, but on HTTP headers. I know you can send this header from PHP code, but that won’t work on a pure HTML page, of course.

You may also be able to do this with .htaccess rules. Simply create a file in your htdocs directory with the name .htaccess and add this line to it:

Header add X-Frame-Options "SAMEORIGIN"

Please note that I did not test this rule, and I don’t know whether it works at all or whether it’s supported in our hosting.

If this doesn’t work, you can also use Javascript to break out of an iframe. Javascript code can be embedded in a static HTML website. You can find plenty of snippets to use by searching the web.

1 Like

This is a Stack overflow question, that can help.
https://www.google.com/search?q=how+to+prevent+my+website+from+being+loaded+into+an+iframe
This is a list of sites that can answer your queston

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.