Thursday 20 December 2012

Prevent User from Opening your Webpage in Iframe Using Javascript


Prevent User from Opening your Webpage in Iframe Using Javascript


Use the following Javascript Code to prevent People from Opening your webpage/HTML page in an iframe:
(Put this javascript in between the head tag of your concerned Page)


<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Iframe Blocker</title>

<script type="text/javascript">

if( (self.parent && !(self.parent===self))

    &&(self.parent.frames.length!=0)){

    self.parent.location=document.location

}

</script>

</head>

<body>

<h1>Cannot Open in Iframe</h1>

</body>

</html>

Alternatively Use this script:


<script type="text/javascript">

//<![CDATA[

    if (window.top !== window.self) {

        document.write = "";

        window.top.location = window.self.location;

        setTimeout(function () {

            document.body.innerHTML = '';

        }, 1);

        window.self.onload = function (evt) {

            document.body.innerHTML = '';

        };

    }

//]]>

</script>

1 comment:

  1. It's a really Helpful code and easy to impliment.

    you did Very Nice Job my friend.

    Thanks
    Parth Pandya

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top