日期:2014-05-16  浏览次数:20348 次

js访问跨域的iframe内容
我使用动态生成隐藏iframe 和 form 的方式进行跨域POST请求  
返回来的数据是在隐藏的iframe中的 
由于跨域 我无法直接使用js获取iframe响应后的内容
代码如下:
          var iframe = document.createElement("iframe");
          var iframeName = "crossDoamin";
          iframe.style.display = "none";
          iframe.name = iframeName;  
          document.body.appendChild(iframe);

            var form = document.createElement("form");
    form.action = "http://xxxxxxxxx.action";
    form.method = "POST";
    form.target = iframeName;
    form.style.display = "none";

    //repeat for each parameter
    var input_pid = document.createElement("input");
    input_pid.name = "xxx";
    input_pid.value = xxx;
    form.appendChild(input_pid);
    
    var input_sname = document.createElement("input");
    input_sname.name = "xxxx";
    input_sname.value = xxxx
    form.appendChild(input_sname);
    //append the form and submit
    document.body.appendChild(form);

            form.submit();

这样我在隐藏的iframe中返回了我的数据
现在如何才能跨域获得数据

  像网上提供的postMessage 和 在url后面带hash  我都试过 但是解决不了
希望大神们提供具体的方式 
跨域 iframe

------解决方案--------------------
如果你能动 跨域页面站点的页面,才有可能
------解决方案--------------------
跨域不可能实现。
建议使用服务器代码执行 Request请求