Wix - How do I link an iframe to the main window in HTML?
I have a client who is using a Tripleseat embedded form in an iFrame on Wix, and they wanted us to insert some additional tracking code to track the form submissions. See the code below. The problem was that this embedded iframe code was opening up the thank you redirect page URL inside the iFrame instead of the main mother window. This was fixed by changing the target of the redirect to .top.
We changed: window.location to window.top.location, so the .top addition opens the redirect URL into the mother page/window instead of just inside the iframe.
Original tracking / redirect code:
<script>
TS.custom_success_callback = function(success_message, lead_id) {
// view the success message
// redirect to a custom url
window.location = 'https://www.domain.com/reservations-form-thank-you';
// lead_id is the id of the created lead
// it can be used for custom tracking/analytics
record_new_lead(lead_id);
}
</script>
Fixed code script so that the iframe loads into the mother window/page instead of just inside the iframe:
<script>
TS.custom_success_callback = function(success_message, lead_id) {
// view the success message
// redirect to a custom url
window.top.location = 'https://www.domain.com/reservations-form-thank-you';
// lead_id is the id of the created lead
// it can be used for custom tracking/analytics
record_new_lead(lead_id);
}
</script>
Comments