Tengo una página de WP con iframes incrustados. Hay un widget que cambia el estilo de la página, y necesito que también cambie el estilo de todos los iframes incrustados. El estilo cambia al hacer clic en el botón que tiene el siguiente controlador de eventos:
NightVersionButton.click(function (event) { // this is a part that changes the page style (and it works) event.preventDefault(); Cookies.set('contrast', 'night', { expires: 7, path: window.cookiePath }); body.removeClass('highcontrast highcontrast2 highcontrast3'); body.addClass('night'); // this is a part that should change the style of all iframes, but it does not work due to the error "Uncaught TypeError: single_iframe.contentDocument.body.addClass is not a function" var all_iframes = document.getElementsByTagName('iframe'); for (let single_iframe of all_iframes) { var iframe_doc = single_iframe.contentWindow ? single_iframe.contentWindow.document : single_iframe.contentDocument; iframe_doc.body.addClass('night'); //$(single_iframe).contents().find('body').addClass('night'); // this jQuery alternative does not work neither } });Sin embargo, la parte del código JS responsable de cambiar los estilos en todos los iframes no funciona, con el error de consola "Error de tipo no detectado: single_iframe.contentDocument.body.addClass no es una función".
¿Podría sugerir la solución correcta sobre cómo cambiar el JS que también aplicará addClass a todos los iframes?