I have an iframe with a form, when the form is completed, it has an event listener sending the message "Successful". I then need to get the parent page to redirect to another page e.g "https://website.com/successful".
What else can I add in the JS code to make the parent page redirect once the message "Successful" loads within the iframe.
<script>
document.addEventListener('DOMContentLoaded', function () {
window.addEventListener('message', function (e) {
const data = JSON.parse(e.data);
console.log(data.message);
});
</script>
you can just use window.location.replace like
<script>
document.addEventListener('DOMContentLoaded', function () {
window.addEventListener('message', function (e) {
const data = JSON.parse(e.data);
console.log(data.message);
window.location.replace("https://website.com/successful");
});
</script>