如何使用jQuery将src设置为iframe? [英] How do I set the src to an iframe with jQuery?

查看:204
本文介绍了如何使用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.

这篇关于如何使用jQuery将src设置为iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆