This is a basic template project for a Svelte app that can be embedded in another page using an iframe and the iframe-resizer
library.
The iframe creation and init code is wrapped to allow embedding using a single <script>
tag.
npm install
npm run dev
<script>
tag / dynamic embed sizingTo embed this project in another page, deploy the project and add the following script tag to the page you want to embed the app in:
<script async src="https://<your_deployed_domain>/embed.js"></script>
For example:
<script async src="https://svelte-embed.vercel.app/embed.js"></script>
<iframe>
tag / fixed embed sizingIn cases where <script>
tags are not allowed it is not possible to resize the iframe to fit its content, but you can still embed using an <iframe>
tag directly, fixing the dimensions in the style
attribute. For example:
<iframe src="https://svelte-embed.vercel.app/" style="border: none; width: 500px; height: 400px"></iframe>
This project should deploy to Vercel as-is, with no additional configuration, but you can also deploy to any other static hosting provider.
This uses an iframe resizer to allow the embedded app to resize the iframe to fit its content. embed.js does the following:
border: none; width: 100%;
src
(defaults to /
, or the value of data-src
if it exists, relative to the domain the script is hosted on)iframe-resizer
library on load
From here, iframe-resizer
will handle resizing the height of the iframe in the parent page to fit the content of the embed.