使用任何网络语言,如何在我的页面中保留iframe?

时间:2012-07-26 05:25:11

标签: html iframe

好的,所以我正在尝试iFrame一个网页。我不知道为什么,但它不会停留在我的页面中(它会弹出并进入主页面)。我正在使用的代码是:

<iframe>http://mywebsite.com</iframe>

如何将其保存在我的网站中?

2 个答案:

答案 0 :(得分:3)

试试这个:

<iframe src="http://mywebsite.com"></iframe>

答案 1 :(得分:2)

您需要使用src属性。

<iframe src="http://mywebsite.com"></iframe>

放置在iframe代码中的HTML /文本内容被视为“后备”内容,只有在浏览器不支持iframe时才会显示。有关详细信息,请参阅MDN documentation

<iframe src="http://mywebsite.com">
    This sentence only shows up if the browser doesn't support iframes!
</iframe>

因此,您创建的iframe未指向具有src属性的任何页面(因此它保持空白),并将文本“http://mywebsite.com”作为后备文本显示在不支持iframe的浏览器。

修改

如果您不控制网站,框架网站可能会有一些逻辑,如:

// if we are not the highest frame, someone is try to frame this site
if(window.parent != window)
    // redirect the framing parent site to our site
    window.parent.location.href = 'http://iframedsite.com';

此逻辑检测网站是否被其他人(例如您自己的网站)嵌入并重定向父框架。您可以通过简单地构建IANA的网站https://www.iana.org/(或仅http://www.example.com)来确认这是否是问题,该网站在框架状态下可以很好地播放,并且不会进行父框架重定向。