-3

How do I block my website from an iframe? For Instance YouTube cannot appear in a iframe it will say in place the owner of this website have blocked iframes. i am aware of the meta tag way like this

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

howerver that does not work for me, is there any other way, i would prefer to use javascript and html no apachi php ajex or others please. this is the youtube iframe that i wish to block just with my site. also without .htaccess

   <!DOCTYPE html>
<html>
<head>
<title>YouTube</title>
</head>
<body>
<iframe width="50%" height="50%" src="http://www.youtube.com" >
</iframe>
</body>

Universal Omega
  • 206
  • 1
  • 5
  • 26

1 Answers1

0

My solution is to put in head or body tag

<script type="text/javascript">
function PreventFrame() {
    try {
        if (window.top !== window.self) {
            document.write = "";
            window.top.location = window.self.location;
            setTimeout(function() {
                document.body.innerHTML = '';
            }, 0);
            window.self.onload = function() {
                document.body.innerHTML = '';
            };
        }
    } catch (err) {}
}
PreventFrame();
</script>
Rtra
  • 514
  • 12
  • 25