Solution 1 :

I have used the post message method more about that here

on the sending end I’ve used window.parent.postMessage('Message', '*'); the window.parent specefies to send the message to the parent of the iframe which is my website, on the receiving end (on my site) I’ve used window.addEventListener("message", function(message){ more code });

this does it for me, thank you

Problem :

I’m coding a site where I wan’t to embed an iframe, the iframe is coded on a different domain/ origin and I wan’t to send an string to my website (javascript of the site) everytime I click a button, I can’t use sessionstorage or localstorrage because the iframe is not on the same origin as the site!

update

I’ve tried using postmessage, this method is new for me, I’ve been able to receive messages that I send from the console but I can’t send messages from my iframe for some reason, It doesn’t work this is the code for the button that needs to send the message <img id="play"src="https://image source" alt="play" onclick="window.postMessage('{{YTID}}', '*');" height="100" width="100">
the button shows up but it won’t send.

I think it has something to do with the window but I don’t know what the right DOM for the receiving window would need to be.

Comments

Comment posted by developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Comment posted by Tijl Gyssels

wow thank you, I’ve implemented this in my site , but for some reason, it won’t send, I can read messages I send from the console and use them but it won’t send from the iframe , I’m using

Comment posted by kosmos

Update (edit) your question providing your current (and relevant) code.

By