Код: Выделить всё
useEffect(() => {
// Listen for messages from the iframe
const handleNavigation = (event) => {
console.log('Received message in React:', event);
if (event.data && event.data.type === 'NAVIGATE') {
window.location.href = event.data.path; // Directly navigate to the new URL
}
};
window.addEventListener('message', handleNavigation);
return () => {
window.removeEventListener('message', handleNavigation); // Cleanup listener
};
}, []);
Код: Выделить всё
.on('click', function () {
console.log('Button clicked in jQuery!');
// Send a message to React to navigate
window.postMessage({ type: 'NAVIGATE', path: '/port' }, '*');
});
Подробнее здесь: https://stackoverflow.com/questions/791 ... ery-plugin
Мобильная версия