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 Commented 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.)

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, that explains it. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.