onMessage to html not passing

page code:
$w.onReady( () => {
$w(“#dataset1”).onReady( () => {
let itemObj = $w(“#dataset1”).getCurrentItem();
console.log(“i got “+ itemObj.total); //works!! shows the correct data
//so send it to my html #bar1
$w(”#bar1”).postMessage(itemObj.total);

} );
the code on html #bar1
<!doctype html>

var reData; window.alert("start work now==>"); //this doesn show any thing wired??? window.onmessage = (event) => { if (event.data) { reData = event.data; window.alert("gort " + reData); //this doesn show any thing wired??? window.parent.postMessage("send To page code", reData); $("h3").text(reData); }} nothing happend all 3 options dont show any thing whats wrong?

You don’t have an onMessage() event handler in your HTML code. See Corvid: Working with the HTML Element for details on what you need to do for message passing.

window.onMessage = (event) => {
if (event.data) {
reData = event.data;
window.alert("gort " + reData);

still nothing happend

I believe that window.alert() will not work. Try using console.log() and then check the results in the browser’s developer’s console.

Follow the example in the article and build a test page with a test HtmlComponent . Once you get that working you can then use it on your own site.

i tried using console.log()
and what i get in eveloper console output

  1. Loading the code for the HOME page. To debug this code, open cjg9.js in Developer Tools.

  2. i got 234.24
    here is the full html code

meter { --background: #dadada; --optimum: forestgreen; --sub-optimum: gold; --sub-sub-optimum: crimson;

/* The gray background in Firefox */
background: var(–background);
display: block;
margin-bottom: 1em;
width: 100%;
}

/* The gray background in Chrome, etc. */
meter::-webkit-meter-bar {
background: var(–background);
}

/* The green (optimum) bar in Firefox */
meter:-moz-meter-optimum::-moz-meter-bar {
background: var(–optimum);
}

/* The green (optimum) bar in Chrome etc. */
meter::-webkit-meter-optimum-value {
background: var(–optimum);
}

/* The yellow (sub-optimum) bar in Firefox */
meter:-moz-meter-sub-optimum::-moz-meter-bar {
background: var(–sub-optimum);
}

/* The yellow (sub-optimum) bar in Chrome etc. */
meter::-webkit-meter-suboptimum-value {
background: var(–sub-optimum);
}

/* The red (even less good) bar in Firefox */
meter:-moz-meter-sub-sub-optimum::-moz-meter-bar {
background: var(–sub-sub-optimum);
}

/* The red (even less good) bar in Chrome etc. */
meter::-webkit-meter-even-less-good-value {
background: var(–sub-sub-optimum);
}

Featured Offers

makes no sence

Not the Editor’s console, but the Browser’s console.


Console.log() output in an HtmlComponent won’t appear in the Editor’s console

didnt find the view but found Chrom devTools console
and got this output

console.js:35 Loading the code for the HOME page. To debug this code, open cjg9.js in Developer Tools.
console.js:35 [onReady callback registered] on wix-dataset
console.js:35 [Dataset - Connected] ‘total’ collection to element ‘#text10’: {text: “total”}
console.js:35 [Dataset - Populated] ‘total’ collection into element ‘#text10’: {text: “234.24”}
console.js:35 [datasetReady event] triggered on wix-dataset
console.js:35 [wix-dataset.getCurrentItem] called
console.js:35 [wix-dataset.getCurrentItem] returned with ( {“_id”:“e65decb1-872f-407b-aed5-cf229f21f10c”,“_owner”:“d9c386b6-a60e-4c95-9eda-3491fc01b73b”,“_createdDate”:“2020-02-02T08:47:05.495Z”,“kasar”:1,“_updatedDate”:“2020-02-06T09:01:58.976Z”,“total”:234.24} )
console.js:35 i got 234.24
get_draft?id=d9c386_5fd11d7e1a788e0d77a23eefcd651be4.html:6 start work now
get_draft?id=d9c386_7243ebb532adeb830ab795924079ac53.html:6 start work now
.lp:5 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/.
EnvSendPing @ .lp:5
EnvDisconnect @ .lp:10

notice there is deprecation warrning what is this?

so we are back to square 1
onMessage() is not performed I received a warrning .lp5[Deprecation] Sychronus …and run is stoped
what’s wrong?

:exploding_head: I nearly deprecated in my pants when I read that message.

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

I’ve got to see this for myself.

יםצק

home page

https://editor.wix.com/html/editor/web/renderer/edit/4abbf358-e36d-44a8-821d-dda249b0176d?metaSiteId=c26711f5-60fe-4de3-a536-93eef2713a71&editorSessionId=68425fcb-3f0d-4083-974e-b8cc04b11078&referralInfo=dashboard

Not sure what’s going on, but you’ve got a pile of errors in the progressbar.js file in Public. I don’t see it being used so I would recommend deleting it for now.

I’m getting some other errors but I don’t know where they’re from. Are you using any code in Tracking and Analytics?

Meanwhile, I’m still playing with it.

OK, so I just discovered that you’ve got two HtmlComponents on the page. When I deleted the other one (#html1) most of the errors disappeared.

And…

From what I see, you are trying to use HtmlComponents to display progress bars. Why not just use Wix’s ProgressBar instead? It’ll be much easier and cleaner to code it. That’s what I would recommend.