如何将用户脚本发布到angularJS中的$ window.open方法

时间:2017-01-31 10:13:33

标签: javascript angularjs webview window.open userscripts

我想打开 - https://myUI:88/openURL/(例如:点击按钮,它应该重定向到此https://myUI:88/openURL,就像在支付网关中发生的那样)然后,我必须通过以下用户脚本:

getRealData('{"mailing":{"postalCode":"111","city":"NJ"},"terminal":"222"}');

如何在AJS 1.x中实现这一目标?

getRealData是https://myUI:88/openURL网络应用

中的公共方法

1 个答案:

答案 0 :(得分:0)

您可以使用window.postMessage()API在父窗口和子窗口之间传递数据。

在Parent js文件中:

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

在孩子的js文件中:

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)

}