This document explains the technical architecture and code flow of MagicFrame.
MagicFrame is a single HTML file that creates a full-page iframe with enhanced functionality. The system is designed to be simple, lightweight, and dependency-free.
┌─────────────────────────────────────────┐
│ MagicFrame │
│ │
│ ┌─────────────────────────────────┐ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ iframe │ │
│ │ (Target Website) │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ └─────────────────────────────────┘ │
│ │
└─────────────────────────────────────────┘
The entire solution consists of a single HTML file with three main components:
- HTML Structure: Defines the iframe element
- CSS Styling: Ensures the iframe fills the entire viewport
- JavaScript Logic: Handles URL parameter passing and title synchronization
<body>
<iframe id='forwardFrame' name='forwardFrame' src='' width='100%' height='100%'
marginheight='0' marginwidth='0' scrolling='auto' frameborder='0'>
<p>Your browser does not support iframes.</p>
</iframe>
<!-- JavaScript code here -->
</body>html, body {
margin: 0px;
padding: 0px;
overflow: hidden;
height: 100%;
}The JavaScript component has two main responsibilities:
-
URL Construction and Loading:
var url = 'http://example.com'; // Target URL (configurable) frame.src = url + window.location.search + window.location.hash;
-
Title Synchronization:
frame.onload = function() { document.title = document.getElementById('forwardFrame').contentWindow.document.title; }
The following diagram illustrates the execution flow of MagicFrame:
┌──────────────┐ ┌───────────────────┐ ┌───────────────────┐
│ User visits │ │ MagicFrame loads │ │ iframe loads with │
│ MagicFrame ├────►│ iframe with ├────►│ target content │
│ URL │ │ constructed URL │ │ │
└──────────────┘ └───────────────────┘ └─────────┬─────────┘
│
┌───────────────────┐ │
│ Browser displays │◄─────────────┘
│ content & updates │
│ page title │
└───────────────────┘
One of MagicFrame's key features is preserving URL parameters and hash fragments. Here's how it works:
Original URL: https://yourdomain.com/magicframe/?user=123&view=dashboard#settings
└───────────┬──────────┘ └──┬───┘
│ │
Query Parameters Hash Fragment
│ │
▼ ▼
Target URL: https://example.com/?user=123&view=dashboard#settings
└─────┬─────┘ └───────────┬──────────┘ └──┬───┘
│ │ │
Base Target URL Query Parameters Hash Fragment
The title synchronization process occurs after the iframe content has fully loaded:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ iframe content │ │ onload event │ │ Page title │
│ finishes ├────►│ handler ├────►│ updated to │
│ loading │ │ triggered │ │ match iframe │
└─────────────────┘ └─────────────────┘ └─────────────────┘
-
Same-Origin Policy: The title synchronization will only work if the target URL is on the same origin or has appropriate CORS headers.
-
X-Frame-Options: If the target site sets
X-Frame-Options: DENYorX-Frame-Options: SAMEORIGIN, it cannot be displayed in an iframe. -
Content Security Policy: Some websites implement CSP rules that prevent them from being loaded in iframes.
For more information on these limitations, see the Security Considerations page.