Hi Everyone,
I have a jsp page which will send info by the postMessage function.
eg:
window.postMessage(object, webappbuilderAppURL);
Then I am able to retrieved it by the following lines.
eg:
window.addEventListener("message", onMessageReceived, false);
function onMessageReceived(aEvent) {}
but it ONLY works inside the index.html page.
The question I have is, how can I pass the "object' to my widget?
is there any functions like publishData/onReceiveData/fetchDataByName in the widgets from the index.html page?
Thanks!
Solved! Go to Solution.
What about something like:
index.html {
window.MyPostData = {};
window.addEventListener("message", onMessageReceived, false);
function onMessageReceived(aEvent) {
window.MyPostData = aEvent.myResultsInterestedIn;
dojo.topic("myapp/postDataReady");
}
}
myWidget.js {
onStartup: function(){
if (window.MyPostData === {}) {
dojo.topic.subscribe("myapp/postDataReady", function(){ call_Init });
}else{
call_Init()
}
}
}
Thanks for you message Robert,
dojo/topic is really handy to pass external data to the widgets!
Thanks
Xiaoqing
What about something like:
index.html {
window.MyPostData = {};
window.addEventListener("message", onMessageReceived, false);
function onMessageReceived(aEvent) {
window.MyPostData = aEvent.myResultsInterestedIn;
dojo.topic("myapp/postDataReady");
}
}
myWidget.js {
onStartup: function(){
if (window.MyPostData === {}) {
dojo.topic.subscribe("myapp/postDataReady", function(){ call_Init });
}else{
call_Init()
}
}
}
Thanks for your reply Jordan! The window.MyPostData works like a charm!
And there is no need to use dojo/topic, the following lines work in my WAB app.
index.html {
window.MyPostData = {};
window.addEventListener("message", onMessageReceived, false);
function onMessageReceived(aEvent) {
window.MyPostData = aEvent.myResultsInterestedIn;
}
}
myWidget.js {
onStartup: function(){
if (window.MyPostData === ...) {
call_Init()
}else{
}
}
}
Thanks!!