I am using this code on a page with a video stream to prevent people from iframe it:
<script>if(self != top) { top.location = self.location; }</script>
but now i would like to allow one or more domains to embed the page using iframe. I looked on stackoverflow and found this:
<script type="text/javascript">
if (window.top.location.host != "website.com") {
document.body.innerHTML = "Access Denied";
}
</script>
But it doesn't work. I know there must be a way because i remember 2 years ago a website that had something like this and when i tried to embed their page with iframe, it redirected me to an adult website and the iframe only worked on their domain.
Looks like i solved the problem
<script>
if (top.location.host != "example.com") {
window.location.href='http://example.com/redirected';
}
</script>