Estoy tratando de trabajar en los contenidos de iFrame y el siguiente fragmento no devuelve el valor de h1 de la URL de iFramed. En su lugar, alerta undefined . ¿Puede alguien sugerir qué está mal aquí?
<!doctype HTML> <head> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> </head> <body> <button id="myBtn">Login</button> <br><br> <iframe name="SSOBlock" id="SSOBlock" src="https://www.example.com/" ></iframe> <script> $("#myBtn").click(function(e) { e.preventDefault(); alert($('iframe[name=SSOBlock]').contents().find('h1').html()); }); </script> </body> </html>