How do I set the src to an iframe with jQuery?

Alex picture Alex · Jun 6, 2013 · Viewed 66k times · Source

My iFrame looks like this:

<iframe id="iframe" name="iframe1" frameborder="0" src=""></iframe>

And my script looks like this:

<script type="text/javascript">
    $(document).ready(function() {
    $('#iframe').attr('src',http://google.com);
})
</script>

I've also tried putting quotes around the url:

<script type="text/javascript">
    $(document).ready(function() {
    $('#iframe').attr('src','http://google.com');
})
</script>

But neither is working.

What am I missing?

Answer

SLaks picture SLaks · Jun 6, 2013

If you look at the browser's error console, you'll see the real problem:

Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Google doesn't let you do that.