如何使用jQuery将src设置为iframe?

如何使用jQuery将src设置为iframe?

问题描述:

我的iFrame看起来像这样:

My iFrame looks like this:

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

我的脚本如下所示:

<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>

但两者都不起作用。

我缺少什么?

如果你看一下浏览器的错误控制台,你会看到真正的问题:

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


拒绝显示' https://www.google.com/ '在一个框架中,因为它将'X-Frame-Options'设置为'SAMEORIGIN'。

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

Google不允许你这样做。

Google doesn't let you do that.