P
P
Pavel2021-02-19 14:18:54
JavaScript
Pavel, 2021-02-19 14:18:54

How to close ifmame after registration is completed?

There is a site on which a person registered in a loyalty program on another site before buying. In the instructions on how to do this, they gave the code for the "Listening" script. Which, after successful registration, should return the client back to the cart, it does not work. Registration passes and after pressing the "OK" button in the iframe does not return.
The script itself tried to add both to the head and to the body, nothing works. Maybe either the instructions made a mistake with the code or I'm a fool, but I don't understand why it doesn't work

JS code

<script>
      var eventMethod = window.addEventListener
                   ? "addEventListener"
                   : "attachEvent";
    var eventer = window[eventMethod];
    var messageEvent = eventMethod === "attachEvent"
           ? "onmessage"
           : "message";
  
    eventer(messageEvent, function (e) {
          
    if (e.data === 'iframe_process_complete') {
              console.log('Complete iframe registration');
              return;
          }
  
}

        try {
              const data = JSON.parse(e.data);
              window.location.href = data.redirectUrl;
  
              
               data = {
                 redirectUrl: 'сайт'
               };
              
          } catch (error) {
               
          }
  });
  </script>


also gave the code "closing the iframe" but the page does not work with it at all or I inserted it in the wrong place, put it at the end of the code
if (window && window.parent) {
window.parent.postMessage('{"message": " http://"}', '*');}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question