[HTML/JS] Problema con Element.setAttribute

Iniciado por Ori-chan, 1 Mayo 2014, 13:44 PM

0 Miembros y 1 Visitante están viendo este tema.

Ori-chan

El problema es que no aparece la página de google en el iframe y no se porqué.


Código (actionscript-french) [Seleccionar]
<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to make a BUTTON element.</p>

<button onclick="crear_frame()">Anadir iframe</button>

<script>
function crear_frame()
{
var link = "http://www.google.com"
var frame=document.createElement("iframe");
frame.width="300px";
frame.height="250px";
frame.setAttribute("align", "center");
frame.id="iframe";
frame.setAttribute("src", link);
document.body.appendChild(frame);
document.getElementById("ad54").appendChild(frame);
}
</script>


<div id="ad54">hola</div>
</body>
</html>





Muchas gracias por leer!!


Pablo Videla

Tu código esta bien, el problema es que google por razones de seguridad no te deja entrar a su sitio desde otros dominios, lo verifique buscando el error que me salia

Este es el error que me arroja

CitarRefused to display 'https://www.google.cl/?gfe_rd=cr&ei=_EtiU5rtIoeF8QfhsYH4Bg'; in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Buscando el error me encuentro con esto.
Citar

Yes, that is correct. the Googles response header has X-Frame-Options set to SAMEORIGIN meaning that you can access google only from some other page hosted on google.com and not from anywhere else.
Fuente : http://stackoverflow.com/questions/22012933/refused-to-display-in-a-frame-in-a-frame-because-it-set-x-frame-options-to-sa

Para ver los errores javascript, debes ver la consola de tu navegador.

Ori-chan

¡Muchas gracias! Ahora podré terminar mi trabajo.  ;D

¿Por que querrá google que no se pueda entrar a su buscador desde otro dominio?..


Pablo Videla

Cita de: Ori-chan en  1 Mayo 2014, 15:38 PM
¡Muchas gracias! Ahora podré terminar mi trabajo.  ;D

¿Por que querrá google que no se pueda entrar a su buscador desde otro dominio?..

Por lo que he leído en otros lados tiene que ver que no puedes ver en un iframe con SSL en un dominio sin SSL y sin certificados de seguridad, pero deben haber muchas mas razones todavía.