Rishi Kumar Rishi Kumar - 2 months ago 12
HTML Question

how to block website from loading in iframe?

Recently i tried to load youtube website in an iframe, but i checked that it's not worked. i used this simple code.

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<iframe width="1000px" height="700px" src="http://www.youtube.com" ></iframe>
</body>
</html>



  1. i want to know , why my webpage can't load youtube website in
    iframe..

  2. what code i use to load the youtube website in my webpage.

  3. how i use same techniq in my website, so no one can add my website
    in iframe.


Answer

You can use HTTP Header Field X-Frame-Options,

  <meta http-equiv="X-Frame-Options" content="deny">

There are three possible values for X-Frame-Options:

DENY - The page cannot be displayed in a frame, regardless of the site attempting to do so.

SAMEORIGIN - The page can only be displayed in a frame on the same origin as the page itself.

ALLOW-FROM uri - The page can only be displayed in a frame on the specified origin.