how can i pass the data from child window to parent window using lightning web component
- to populate the new window i used this code popup = window.open("fileName", "Popup", "width=600,height=700"); popup.focus();
Use the Lightning Message Service to communicate between windows.
Source Example:
// myPublisherComponent.js
import { LightningElement } from 'lwc';
import { createMessageContext, releaseMessageContext,
publish } from 'lightning/messageService';
import SAMPLEMC from "@salesforce/messageChannel/SampleMessageChannel__c";
export default class MyPublisherComponent extends LightningElement {
context = createMessageContext();
publishMC() {
const message = {
recordId: "some string",
recordData: { value: "some value" }
};
publish(this.context, SAMPLEMC, message);
}
disconnectedCallback() {
releaseMessageContext(this.context);
}
}
Destination Example:
import { LightningElement, track } from 'lwc';
import { createMessageContext, releaseMessageContext
subscribe, unsubscribe } from 'lightning/messageService';
import SAMPLEMC from "@salesforce/messageChannel/SampleMessageChannel__c";
export default class MySubscriberComponent extends LightningElement {
context = createMessageContext();
subscription = null;
@track receivedMessage = '';
subscribeMC() {
if (this.subscription) {
return;
}
this.subscription = subscribe(this.context, SAMPLEMC, (message) => {
this.handleMessage(message);
});
}
unsubscribeMC() {
unsubscribe(this.subscription);
this.subscription = null;
}
handleMessage(message) {
this.receivedMessage = message ? JSON.stringify(message, null, '\t') : 'no message payload';
}
disconnectedCallback() {
releaseMessageContext(this.context);
}
}
Create custom events and dispatch them from the child component to parent component. Refer to this link: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.events_create_dispatch
message
event, and even then, you wouldn't construct an eent for that.