【问题标题】:Website not showing on iframe even using jquery即使使用 jquery,网站也没有在 iframe 上显示
【发布时间】:2014-04-19 06:44:43
【问题描述】:

我正在使用此代码在 iframe 中显示 http://www.solstas.com/find-a-location/

<iframe src="http://www.solstas.com/find-a-location/" width="837" height="544"> 
</iframe>

而这段代码使用jquery:

$("#siteloader").html('<object data="http://www.solstas.com/find-a-location/">');

但它没有显示任何内容,我尝试了其他网站然后它可以工作。有人说这可能是因为该站点设置了 X-Frame-Options。

请帮忙。

【问题讨论】:

  • 请贴出相关的html和javascript,信息不足。
  • 嗯,那个网站是否设置了 X-Frame-Options 标头?
  • 没有示例代码,其他人帮助你是不容易的。请用一些示例更新您的问题。
  • 我正在使用jsfiddle.net/SsJsL 来测试我的代码。 @EdCottrell 我真的不知道该站点是否设置了 X-frame-options
  • 如果在该站点中设置了 X-Frame-Options,是否意味着您不能对该站点进行 iframe? ..即使使用 jquery 也行不通?

标签: jquery html iframe x-frame-options


【解决方案1】:

你可以试试:

 $("#siteloader").append($('<iframe width="837" height="544" src="http://www.solstas.com/find-a-location/"></iframe'));

【讨论】:

  • 我也在jsfiddle.net/SsJsL 中尝试过这段代码,但它没有显示..tnks 为你们的帮助..
【解决方案2】:

您将无法对此进行构图,因为该站点使用X-Frame-Options。我做了这个请求:

GET /find-a-location HTTP/1.1
Host: www.solstas.com

得到了这样的回应:

HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 176
Content-Type: text/html; charset=utf-8
Location: /error/internal-server-error?aspxerrorpath=/find-a-location
Server: Microsoft-IIS/7.5
X-Umbraco-Version: 4.7
Set-Cookie: UserLatitude=29.8301; path=/
Set-Cookie: UserLongitude=-95.4739; path=/
X-Powered-By: ASP.NET
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Date: Fri, 14 Mar 2014 06:15:15 GMT

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/error/internal-server-error?aspxerrorpath=/find-a-location">here</a>.</h2>
</body></html>

X-Frame-Options: SAMEORIGIN 表示此页面不应显示在框架中,包括 iframe。实际上,这意味着你做不到,因为几乎所有现代浏览器都会遵守这个要求。

【讨论】:

    【解决方案3】:

    这是将iframe源加载到jquery的代码

    $(document).ready(function() {
        $('#iframe').attr('src', 'http://www.solstas.com/find-a-location/');
    });
    

    注意:如果该域 (www.solstas.com) 允许跨域框架,这将起作用

    【讨论】:

    • 我已经在那里添加了原因作为注释。请检查任何其他支持跨域框架的站点以检查该代码。
    • 其实“solstas.com/find-a-location”站点显示内部服务器错误,iframe没有问题
    猜你喜欢
    • 1970-01-01
    • 2022-07-14
    • 2022-12-12
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-05
    相关资源
    最近更新 更多