我的网页中内嵌一个iframe,iframe中的网页在变化,请问如何在我的网页中用js获取iframe中的网页的网址和标题?

解决方案 »

  1.   

    function getsrc(){
    var a,b
    a=document.getElementById("iframeid").src
    b=document.getElementById("iframeid").title
    alert(a,b);
    }
      

  2.   

    1楼的办法不行,src只能得到初始的网页,当iframe中网页变了后,取不到,另外我正在是window.frames["frameid"].location但是能赋值,不能读取,读取出错,而window.location能行,郁闷
      

  3.   

    如果没跨域,这个就可以
        <iframe id="f1" src="test.html"></iframe>
     </body>
     <script type="text/javascript">
     
    document.onclick=function(){
        var f1=window.frames["f1"];
        alert(f1.location.href+"\n"+f1.document.title)
    }
      

  4.   

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="index.aspx.vb" Inherits="_Default" %><!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 runat="server">
        <title>PJTest</title>
        <%--<frameset cols="25%,*">
            <frame id="menu" src="menu.aspx"></frame>
            <frame id="info" src="info.aspx"></frame>
        </frameset>--%>
        <script type="text/jscript" src="jscript.js" language="jscript"></script>
        <script type="text/jscript" src="http://code.jquery.com/jquery-latest.js"></script>
        <link type="text/css" href="StyleSheet.css" rel="stylesheet" />
        <style type="text/css">
            #form1 {width:100%;height:100%;background:#EEE;}
            #divForm {width:100%;height:80%;background:#EEE;}
            #menu {width:100%;height:20%;position:absolute;top:50;left:0;border:0;padding:0;margin:0;}
            #info {width:100%;height:80%;position:absolute;top:20%;left:0;}
        </style>
        <script>
        function getSrc(){
        alert(window.frames["menu"].location  );
        alert(window.frames["menu"].document.title  );
        }
        function setSrc(){
        window.frames["menu"].location="info.aspx";
        }
        </script>
    </head>
    <body onload="mainLoad();">
        <form id="form1" runat="server">
        <input type=button onclick="getSrc();" value=get>
        <input type=button onclick="setSrc();" value=set>
        <div id="divForm">
            <iframe id="menu" src="menu.aspx"></iframe>
            <iframe id="info" src="info.aspx"></iframe>
        </div>
        </form>
    </body>
    </html>
      

  5.   

    sohighthesky提醒我了,我试了下,应该是跨域的问题,本地的网页用shan1119和sohighthesky方法都可以,各位跨域怎么处理
      

  6.   

    主要问题是iframe中的网页是别的网站的,我想访问到iframe中网页的url和标题
      

  7.   

    alert(document.getElementById("iframeid").title)。没有显示任何东西.typeof 后为string