【问题标题】:iframe src url changing the parent url unintentionallyiframe src url 无意中更改了父 url
【发布时间】:2012-05-31 10:13:54
【问题描述】:

我们正在通过 iframe 从我们的网站 (www.example.com) 调用 api 服务器 (api.example.com)。

当我们进行调用时,iframe 源 url 将父窗口 url 更改为 iframe 源 url。下面给出的是 iframe 代码:

<iframe onload="iframeManager.tempIframeCallback()" id="xd_iframe" allowtransparency="true" frameborder="0" scrolling="no" tabindex="0" name="xd_iframe" style="position:absolute;top:-9999em;width:10px;height:10px;" src= "{{html on api server}}">
        </iframe>

下面是api服务器上的html:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <title>xyz</title>

  <body>
    <script type="text/javascript" charset="utf-8">
        document.domain='example.com';
    </script>
  </body>
</html>

参考:http://fettig.net/weblog/2005/11/28/how-to-make-xmlhttprequest-connections-to-another-server-in-your-domain/

【问题讨论】:

  • 你为什么使用 iframe?为什么不调用 ajax 来加载页面/数据?

标签: javascript jquery iframe cross-domain


【解决方案1】:

您所指的文章写于 2005 年!现在,大多数现代浏览器都支持 CORS,只要服务器允许,您就可以干净地进行跨源 AJAX。这是一篇博客文章,解释了如何:http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-27
    • 2014-06-17
    • 2010-12-24
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    相关资源
    最近更新 更多