Outsystems技术问题:如何结合Header Block使用ExternalSite
Absolutely! You totally can load an ExternalSite alongside your app's Header Block while keeping the external content embedded right within your application—this is a super common pattern for building wrapped experiences or portal-style apps. Here's how you can pull this off:
1. Wrap Both Components in a Parent Container
The core approach is to create a parent component that renders your persistent Header Block and the ExternalSite component in a stacked layout (headers almost always sit above content). Here's a framework-agnostic example (adjust for React, Vue, Angular, etc.):
// React example (adapt to your tech stack) import HeaderBlock from './components/HeaderBlock'; import ExternalSite from './components/ExternalSite'; function AppPortal() { return ( <div className="app-portal-container"> {/* Your app's fixed header */} <HeaderBlock /> {/* The embedded external site below the header */} <div className="external-content-wrapper"> <ExternalSite url="https://your-target-site.com" /> </div> </div> ); }
2. Make Sure ExternalSite Uses an Iframe (Not Redirects)
For the external site to stay within your app, your ExternalSite component needs to embed content via an iframe instead of triggering a full page redirect. If your current component redirects, rewrite it to use an iframe like this:
// Basic ExternalSite component with iframe function ExternalSite({ url }) { return ( <iframe src={url} title="Embedded External Content" width="100%" height="calc(100vh - 70px)" // Subtract your header's height to avoid overlap frameBorder="0" sandbox="allow-same-origin allow-scripts allow-forms" // Adjust permissions based on needs /> ); }
3. Fix Common Edge Cases
Keep the Header Sticky: Use CSS to fix your Header Block to the top so it stays visible while users scroll the external content:
.app-header { position: fixed; top: 0; width: 100%; z-index: 1000; // Ensure it sits above the iframe background: white; // Add background to cover content behind it }Don’t forget to add top padding/margin to the iframe container to avoid content being hidden under the header.
Handle Cross-Origin Blocks: Some sites block iframe embedding via
X-Frame-OptionsorContent-Security-Policyheaders. If you hit this wall:- Check if the external site offers an official embeddable widget or API
- Use a backend proxy to fetch and serve the content (only if allowed by their terms of service)
Responsive Tweaks: Test on mobile to ensure the header and iframe resize properly—avoid overflow or layout breaks by using relative units like
vhor%.
4. Optional: Add In-App Navigation Controls
If you want to let users navigate the external site without leaving your app, add controls to your Header Block that update the iframe’s src prop:
// Updated HeaderBlock with navigation buttons function HeaderBlock({ onNavigate }) { return ( <header className="app-header"> <h2>My App Portal</h2> <button onClick={() => onNavigate("https://external-site.com/dashboard")}>Dashboard</button> <button onClick={() => onNavigate("https://external-site.com/profile")}>Profile</button> </header> ); } // Updated AppPortal with state for iframe URL function AppPortal() { const [currentUrl, setCurrentUrl] = useState("https://external-site.com"); return ( <div className="app-portal-container"> <HeaderBlock onNavigate={setCurrentUrl} /> <div className="external-content-wrapper"> <ExternalSite url={currentUrl} /> </div> </div> ); }
This setup will keep your app’s header visible at all times while the external site loads and runs within your app’s context.
内容的提问来源于stack exchange,提问作者Lasse Anker

