<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function getBaiDu()
{   //这里通过访问iframe(baidu) 获取frame中的body当中的innerHTML
   //但js当中不允许跨域访问,不知道有什么好的办法没有?
}</script></head><body>
<iframe src="http://baidu.com" name="baidu"></iframe>
</body>
</html>

解决方案 »

  1.   

    js没办法做的,最好是放在服务器端asp的话用xmlhttp
    java的话用httpclient
      

  2.   

    如果只是想得到百度搜索结果,没必要用iframe如果只是想得到iframe中SRC页面的结果,和iframe无关如果只想得到iframe中页面的HTML,和跨域无关
    呵呵,没看懂需要
      

  3.   

    1楼所说有误,JS一样可以得到楼主所说的URL执行后的结果,
    只是后续处理不方便,呵呵,
    <script language="javascript">
    var http_request = false;
    function send_request(url) {//初始化、指定处理函数、发送请求的函数
    http_request = false;
    //开始初始化XMLHttpRequest对象
    if(window.XMLHttpRequest) { //Mozilla 浏览器
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {//设置MiME类别
    http_request.overrideMimeType("text/xml");
    }
    }
    else if (window.ActiveXObject) { // IE浏览器
    try {
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
    if (!http_request) { // 异常,创建对象实例失败
    window.alert("不能创建XMLHttpRequest对象实例.");
    return false;
    }
    http_request.onreadystatechange = processRequest;
    // 确定发送请求的方式和URL以及是否同步执行下段代码
    http_request.open("GET", url, true);
    http_request.send(null);
    }
    // 处理返回信息的函数
    function processRequest() {
    if (http_request.readyState == 4) { // 判断对象状态
    if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
    document.getElementById('area1').innerHTML=http_request.responseText;
    } else { //页面不正常
    alert("您所请求的页面有异常。");
    }
    }
    }
    send_request(url);
    </Script>
      

  4.   

    document.getElementById('baidu').currentWindow.document.你要的东西
    比如 var doc = document.getElementById('baidu').currentWindow.document;elem = doc.getElementById('id'); //这个就是frame里那个页面的节电元素
    elem.innerHTML//这个就是你要的
      

  5.   

    接上
    document.getElementById('baidu').currentWindow.document.body.innerHTML
      

  6.   


    function getBaiDu()
    {
     alert(document.getElementById("baidu").innerHTML);//返回空值
    }
      

  7.   


    我晕倒,ajax也不能跨域啊?
      

  8.   

    要想集成搜索的话,你还是用google 的 Ajax api 吧,简单,想要什么有什么?要javascript 跨域请求的话,除非你能控制被请求的页面,
    iframe 也不能跨域,以前我试过,返回非法请求,
      

  9.   

    想集成搜索的话,你还是用google 的 Ajax api 吧,简单,想要什么有什么?
    楼上的请问这句话什么意思啊?
      

  10.   

       跨区访问iframe内容,我知道一种方法
       就是要多建立俩个iframe,通过另外一个iframe来访问你的iframe
       下面是例子
    主页面代码:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>主页面</title>
    <script language="javascript">
    </script>
    </head>
    <iframe id="baidu" src="http://baidu.com" name="baidu" ></iframe>
    <iframe id="google" src="getDocument2.html" name="google" ></iframe>
    <iframe id="getD" src="getDocument.html" name="getD"></iframe>
    <body>
    </body>
    </html>
    getDocument2.html:
    <html>
    <head>
    <script>
    window.onload = function (){
    alert(3);
    alert(parent.document.frames.length);
    alert(parent.document.frames["getD"].window.document.getElementById('up'));
    alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML);
    }
    function getdocument(){
    alert(4);
    alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML);
    }
    </script>
    </head>
    <body>
    <p id='up'>getDocument2</p>
    <p id='element'>getElement2</p>
    <input type="button" onclick="getdocument();" value="获取iframe"/>
    </body>
    </html>
    getDocument.html:
    <html>
    <head>
    </head>
    <body>
    <p id='up'>getDocument</p>
    <p id='element'>getElement</p>
    </body>
    </html>
    自己运行就可以了