Layui: Assign Child Values to Parent

In the child page, you can assign values to the parent page using the following methods:

  1. Use the window.parent object in JavaScript to access the DOM elements of the parent page and then perform assignment operations. For example:
window.parent.document.getElementById('parentElementId').innerText = 'value';
  1. If the child page and parent page are under the same domain, you can also use the postMessage method for message passing. The child page can send a message to the parent page, and the parent page will then perform assignment operations upon receiving the message. For example:

Send a message in the subpage.

window.parent.postMessage('value', '*');

Receive messages in the parent page and perform assignment operations.

window.addEventListener('message', function(event) {
  document.getElementById('parentElementId').innerText = event.data;
});

By using the above methods, it is possible to assign values to the parent page from a child page.

bannerAds