Reputation: 40
I'm sorry to ask what seems like the same question again.
From my previous question, I set up a live server in visual studio and have opened the count.html via the live server.
in my iframe's <script>
I call the parent functions like window.top.updateValueRight(varName);
. I have also tried window.parent.updateValueRight(varName);
, window.frames.iframe.updateValueRight(varName);
, and
updateValueRight(varName);
It says that that function doesn't exist within the parent function. Originally this was in the parent script.js
but I moved it to the <script>
to ensure communication.
TypeError: window.top.updateValueRight is not a function
When it is indeed a function in my parent's script
function updateValueRight(plusR) {
console.log("recieved right inc")
rightEl.innerText = plusR;
}
I've made sure it's on the same domain but I also tried communicating via postMessage.
in the parent script
function onMessage (event) {
if (event.data != "updateValueRight()"){
updateValueWrong(100);
}else {
updateValueRight(100);
}
}
and I called it with this in the iframe(child) window.parent.postMessage("updateValueRight()",'*');
this doesn't cause any known error, but I'm not receiving my console log, so I believe it is still not properly communicating.
Upvotes: 0
Views: 38