An iFrame (called my_iframe and which has an external domain inside when the user submits myform: https://hpp.sandbox.addonpayments.com/pay) 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):
Try creating the element dynamically. i.e. :
document.body.onload = function() { let form = document.createElement('form'); form.setAttribute('blah', 'foo'); form.addEventListener('bar'); document.body.appendChild(form); window.onmessage = function (msg) { //blah } }
As Whisky, there're many things you can't do in the htmlComponent.
You cannot use: window.open().
Wix doesn't provide support for html code that comes from a third party provider.
https://support.wix.com/en/article/using-iframes-to-display-visible-content-on-your-site
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.
As for using html component, you can add code to pass data to and from the page to the html component and back again.
https://www.wix.com/corvid/reference/$w.HtmlComponent.html
https://support.wix.com/en/article/corvid-working-with-the-html-element