Reputation: 10686
I need some way to detect if site from some URL is framebreaker or not. I mean that Framebreaker - site which brake frame structure if it loaded in a frame.
Upvotes: 1
Views: 761
Reputation: 104
If what you're asking is 'how do I prevent my web page from being viewed in a frame?' then here's the best solution currently known:
Use CSS to set the page's body to not display:
<style>
body { display : none ; }
</style>
Then only display the page if it's not in a frame:
<script>
if (self == top) {
//Not in a frame
document.getElementsByTagName("body")[0].style.display = 'block';
} else {
//In a frame. Redirect to the real page.
top.location = self.location;
}
</script>
Put the style in the <head> and the script in the <body>.
If you just wanted to detect if the page is being framed, but not do anything about it, all you need is the following javascript:
<script>
if(self == top) {
alert("Not in a frame");
} else {
alert("In a frame");
}
</script>
Upvotes: 2
Reputation: 21541
Don't know why you've tagged this as php, only javascript can do this...
if (top !== window) {
top.location.href = '/url/';
}
Upvotes: 0