How to embedding an donation form into an website.
In the most cases the donation-form will be embedded as an iframe.
Goal
At the end of this guide, you will have a donation-form running on a website.
Prerequisites
This guide assumes that you have basic html and js skills. Get an donation_form_id by create an donation_form.
1) Create onmessage
For handling javascript events, we define at first an window.onmessage
block:
navigate
event is used for scroll to the top of the iframe. The gtm-trigger
is used for handling GoogleTagManager events.
2) Resize Iframe
To ensure that the iframe always fits correctly into the page, we need second script block.
The
iframeElement
variable is for reference the iframe element. At load the messageThatIframeIsLoaded
function will assign the element to this variable and post an iframe-loaded
message to the iframe. This will trigger an iframe-height
event that contains the current size of the iframe element. For handling this kind of events, we define the handleIframeMessage
function. In case of an iframe-height
event, the function will set the height of the iframe to the value of the event data.
Finally an event listener for message
is defined for handling the iframe-height
event.
3) Iframe
Finally, the iframe. The donation_form_id
must be adjusted so that the correct campagne can be assigned.
The messageThatIframeIsLoaded
function is defined in the onload interface of the iframe, so the iframe is set directly to the correct size during initial loading.
Last update:
2022-10-04