Having issue with running onready script in published site!

I’m getting my charts javascript to run correctly in preview mode (First Screen Shot), but when I look at the same site published mode (Second Screen Shot) the onready javascript is not running correctly. I believe I’m getting permission issues.

Show me the code (and I think you are running into the “timing” problem. Using the html-comp, aren´t you?). Have you read my article about it (https://girizano.wixsite.com/codecorner/home/html-component-not-running-in-publish-mode-google-sheets-example)?

yes, I’m using an html-comp.

$w.onReady( function () {
//TODO: write your page related code here…
$w(“#dataset1”).onReady( () => {
$w(“#dataset1”).getItems(0,2).then((result) => {
var CTypes=[];
var CTypesCount=[];
var CStages=[];
var CStageCount=[];
var OPNames=[];
var OPNameCount=[];
result.items.forEach( function (item){
console.log(item)
var CTLoc=CTypes.indexOf(item.contractType.title);
if (CTLoc<0) {
CTypes.push(item.contractType.title);
CTypesCount.push(1);
} else {
CTypesCount[CTLoc]++;
}
var CSLoc=CStages.indexOf(item.contractStage.title);
if (CSLoc<0)
{
CStages.push(item.contractStage.title);
CStageCount.push(1);
} else {
CStageCount[CSLoc]++;
}
var OPNLoc=OPNames.indexOf(item.otherPartyName);
if (OPNLoc<0)
{
OPNames.push(item.otherPartyName);
OPNameCount.push(1);
} else {
OPNameCount[OPNLoc]++;
}
});
$w(“#html1”).postMessage([CTypesCount.length].concat(CTypesCount).concat(CTypes).join());
$w(“#html2”).postMessage([CStageCount.length].concat(CStageCount).concat(CStages).join());
$w(“#html3”).postMessage([OPNameCount.length].concat(OPNameCount).concat(OPNames).join());
});
});
});

Yup, you are running into the timing problem on the postMessage. Basically, you are sending data before the component has loaded. Read that article.

Yeah, I read the article. After doing what you recommend it the article, it stopped working even in the preview mode:

html1:

... function ready(){ window.parent.postMessage({"type":"ready"}, "*"); } ...

page code:
$w(“#dataset1”).onReady( () => {

$w(“#html1”).onMessage((event) => {
console.log(event)
$w(“#html1”).postMessage([CTypesCount.length].concat(CTypesCount).concat(CTypes).join())
});

I don’t even see the event message in the console.

Hey,
Why do post the message on the onReady event? Have you tried the following?

$w("#html1").onMessage((event) => {   
  $w("#html1").postMessage([CTypesCount.length].concat(CTypesCount).concat(CTypes).join())    
});

If you don’t see the event message, it means that the event is not fired.

Best,
Tal.