1
votes

I have a booking system embedded into website via iframe - I would like to redirect the user to a Thank You page once the booking has been submitted.

There is a receiveMessage being sent to the parent frame from the booking system iframe, wondering if I can use this as the trigger to redirect the page by adding to the code below?

Thanks in advance

window.addEventListener("message", receiveMessage);
function receiveMessage(e) {
if (typeof e.data !== 'string') return;
if (e.data.search('cliniko-bookings-page:confirmed') > -1) {
var dataLayer = window.dataLayer || (window.dataLayer = []);
dataLayer.push({
'event': 'clinikoBookingCompleted'
});
}
}
</script>```
If the existence of cliniko-bookings-page:confirmed is the criterion, then sure, why not ...? Add it to the end of that if block then. - CBroe
@CBroe - Thanks mate thats great news - would the code look like this? <script type='text/javascript'> window.addEventListener("message", receiveMessage); function receiveMessage(e) { if (typeof e.data !== 'string') return; if (e.data.search('cliniko-bookings-page:confirmed') > -1) { var dataLayer = window.dataLayer || (window.dataLayer = []); dataLayer.push({ 'event': 'clinikoBookingCompleted' window.top.location.href = "http://example.com"; }); } } </script> - Marko
No, not inside the dataLayer.push({...});, but after. - CBroe