How to Check if a Window Is Not an iframe Window Top
The "top" property lets you determine if the opened window is in an iframe or if the window is the parent. The "parent" window is any Web page that contains an internal frame such as an iframe. The Web page within the iframe is the child window. You determine if the page is the parent window to break out of an iframe.
Instructions
-
-
1
Right-click the HTML page that displays in the Web page iframe. Click "Open With," then click your HTML editor in the list of programs.
-
2
Create the JavaScript tags. Add the following tags at the top of the HTML code:
<script type="text/javascript"> </script>
The JavaScript code to detect the iframe is placed in these tags.
-
-
3
Type the following function to determine if the page contains teh "top" property:
if (top.location!= self.location) {
//do something here
}
The code above determines if the HTML page contains the "top" property. If the page is determined as the "top" page, the code within the function runs. You can use any code in the function.
-
4
Add the code in the function to break out of the iframe. This code stops other websites from framing your work, so the user is always directed to the original source. Add the following code to the function:
top.location = self.location.href
-
1