1

I have the following piece of code that should dynamically load an iframe with the Google homepage as an example. The iframe gets created but the src is not loaded:

var theIframe2 = document.createElement("iframe");
theIframe2.setAttribute("id", "main-iframe2");
theIframe2.setAttribute("src", "http://www.google.co.uk");

theIframe2.style.width = "300px";
theIframe2.style.height = "200px"; 
theIframe2.style.position = "absolute";
theIframe2.style.top = "0px";
theIframe2.frameBorder = 1;

var containerDiv2 = document.getElementById('container');
containerDiv2.appendChild(theIframe2);

It's also on jsfiddle here: http://jsfiddle.net/JxhFE/1/

Any advice would be appreciated.

Thanks, Colin.

1
  • 1
    Google prevents you from loading its page in a frame using the X-Frame-Options:SAMEORIGIN
    – Yaniro
    Mar 3, 2012 at 22:22

1 Answer 1

3

You can't show google.co.uk in an IFrame in your domain. Due to security reasons Google only allows it's homepage to be embedded from the same origin. (X-Frame-Options SAMEORIGIN header.)

1
  • Ah, that explains it. Thank you! Mar 3, 2012 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.