An iFrame (called my_iframe and which has an external domain inside when the user submits myform : Error ) is in an iFrame in my web; as can be seen in the code.
My_iframe returns (when the user is done with what it does inside it) a message with information. However, the eventlistener type message (underlined and in bold) never receives it. I have used window.open(‘https://www.google.com’, ‘_blank’); to visually know if any message is received: however, it never gets called when the inner iframe send the message.
Why am I not receiving the message? And, what can I do to get it?
RELEVANT CODE (inside wix html component):
<html>
<head></head>
<body>
<form id="myform" method="POST" action="https://hpp.sandbox.addonpayments.com/pay" target="my_iframe">
// some inputs and submit button...
</form>
<iframe name="my_iframe" width="100%" heigth="80%"> </iframe>
<script type="text/javascript">
var f = document.getElementById('myform');
f.f1.value = "maec";
(function() {
// DOM is available
window.onmessage = (event) => {
// this is a message from page code in Wix
if (event.data) {
// the form data is actualised
}
window.open('https://www.google.com', '_blank'); // if any message event is received, google.com should launch
}
// addEventListener
window.addEventListener('message', function (e) {
window.open('https://www.google.com', '_blank'); // if any message event is received, google.com should launch
});
})();
</script>
</body>
</html>
This is how it visually looks (here you can see both iFrames -the inner one and the html component from wix-, and the form submit button):
So in your case as it comes from https://hpp.sandbox.addonpayments.com, then you need to go back to this third party provider and ask them how to integrate it within Wix.
Thank you! However, it does indeed work… If I use it outside of the message event it opens the window (moreover, the final code is not to open a window, i amb using it because it is a visually clear way to know if the message has been received!)…
However, like said previous, Wix won’t provide you with support for third party code, so you really should be going back to your third party code provider and asking them how they integrate an iframe in an iframe into Wix.
@festivalu22bcn If any script fails, the rest will fail to render, including pending promises. And you won’t get any useful errors from the cdn hosted code. In other words, timing is key, and this solves that. If it’s the iframe, then build the iframe.