Frame Enforcer
Maintain your site's integrity. This script detects if a content page has been loaded outside of its designated frameset ("orphaned") and automatically redirects the browser to the main index, preserving your navigation and layout.
Logic Visualization
How the check works:
if (window.top == window.self)
If Top Window (Browser) equals Self (Current Page),
then the page is NOT in a frame → Redirect Triggered.
Click below to test if this specific page is framed:
Copy the Script
Place this code in the <head> section of your content pages (not the frameset itself).
<script>
// Frame Enforcer Script
// Checks if the current page is the top-most window
if (window.top == window.self) {
// If true, the page is an orphan. Redirect to main frameset.
// Replace 'index.html' with your actual frameset URL.
window.location.href = "index.html";
}
</script>
Frequently Asked Questions
Search engines like Google often index individual content pages (like 'contact.html') rather than the main frameset. Without this script, visitors arriving from search results might see your content without the navigation menu.
Yes. You can customize the 'index.html' path in the script to point to whichever frameset file is appropriate for that specific content page.
No. The script specifically checks if the current window (self) is the same as the top-level window (top). If the page is already loaded inside a frame, the condition fails and the script does nothing.