I’m using Nextjs and on my laptop the code is working as intended
when accessing the page from my Iphone it didn’t load
I’m using it to send data between iframes on two different sites
on the Nextjs project
useEffect(() => {
const handleLoad = () => {
if (iframeRef.current) {
iframeRef.current.contentWindow.postMessage(
{ data },
process.env.IFRAME_LINK
);
}
};
if (iframeRef.current) {
iframeRef.current.addEventListener('load', handleLoad);
}
return () => {
if (iframeRef.current) {
iframeRef.current.removeEventListener('load', handleLoad);
}
};
}, [iframeRef.current]);
Again on a pc/laptop this working
The Iframe site code (Vite React)
useEffect(() => {
const handleMessage = (event) => {
const parentURL = import.meta.env.PARENT_URL;
if (event.origin !== parentURL) return;
let { data } = event.data;
console.log('received');
setUserData(data);
};
window.addEventListener('message', handleMessage);
return () => {
window.removeEventListener('message', handleMessage);
};
}, []);