I want to open - https://myUI:88/openURL/ (eg: On click of a button, it should redirect to this https://myUI:88/openURL , like it happens in payment gateway) and then, I have to pass the below user script to that:
getRealData('{"mailing":{"postalCode":"111","city":"NJ"},"terminal":"222"}');
How to achieve this in AJS 1.x?
getRealData is a public method in https://myUI:88/openURL web app
You can pass data between parent window and child window by using the window.postMessage() API.
In Parent js file :
var childWindow = window.open(childurl);// opens a new window and puts the reference to it in childWindow variable.
childWindow.postMessage(YourMessageJson);//the json should be stringified before sending
In child's js file :
window.addEventListener('message', receivedMessage);//attach event listener to get the event sent by postMessage from your parent.
function receivedMessage(data){ //callback function executed on receiving the message
xhr.open(url) //The http call that you wanted to make from this page (I have just put a dummy xhr call, replace it according to your use case)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.