<input type=button value=changesrc onclick="document.iframeName.location.href='a.asp'">

解决方案 »

  1.   

    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE></TITLE>
    <meta http-equiv="Refresh" content="3">
    <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    <!--function button1_onclick() {
     
     document.aaa.location ="http://www.yahoo.com.cn";
     
    }//-->
    </SCRIPT>
    </HEAD>
    33333333333333
    <BODY><INPUT id=button1 type=button value=Button name=button1 LANGUAGE=javascript onclick="return button1_onclick()"></P>
    <iframe name="aaa" src="http://www.sina.com.cn" height=600 width=600>
    <P></BODY>
    </HTML>
    <SCRIPT LANGUAGE=vbscript>
    <!--
     //-->
    </SCRIPT>
      

  2.   

    <script>
     function changeurl(newurl){
        iframename.location=newurl;
    }
    </script>
      

  3.   

    楼上诸君的方法好像没有作用,我有同样的问题,报出'document.iframeName.location'对象为空或不存在,何解?
      

  4.   

    老兄,应该是这样的:
    <input type=button value=changesrc onclick="yourIframeID.src='yourPage.asp'">
    这样可以直接改变iframe框架指向的页面,呵呵
      

  5.   

    我的iframe里设定了name="rightFrame",会报rightFrame未定义错误,不只是什么原因?
      

  6.   

    to  zhoucm990(枫树) ( ) :<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=unicode">
    <META content="MSHTML 6.00.2800.1170" name=GENERATOR><SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    <!--function button1_onclick() {
     document.rightFrame.location="http://www.sina.com.cn";
    }//-->
    </SCRIPT>
    </HEAD>
    <BODY>
    <INPUT type="button" value="Button" id=button1 name=button1 LANGUAGE=javascript onclick="return button1_onclick()">
    <iframe name="leftFrame" src="http://localhost:8080/myapp/jsp/Navigator.jsp" align="left" width="15%" Height="100%" frameBorder="No" marginwidth="0" marginheight="0" ></iframe>
    <iframe name="rightFrame" src="http://localhost:8080/myapp/jsp/mainFrame.jsp" align="right" width="85%" Height="100%" frameBorder="no" border="no" marginwidth="0" marginheight="0" scrolling="no">
    父页面mainFrame.jsp里点击菜单执行脚本
    javascript:window(或document).rightFrame.location.href="employee.jsp"
    执行时报错:window.rightFrame.location不存在或对象为空
    如果是rightFrame.src=""会报rightFrame未定义
    <P>&nbsp</P></BODY></IFRAME></BODY></HTML>
      

  7.   

    你看清楚,我用的是 ID ,not name
    看看下面的代码.
    在frame 中,name id 用途不一样,这是个特殊的地方,其他的地方,都可以.<iframe name="rightFrame" id="frm" src="yourFirstpage.asp"></iframe>
    <button onclick="frm.src='yourWantedPage.asp'">改变iframe框架指向的页面</button>
      

  8.   

    iframe比较特殊,用name,会认为是一个window对象,用id则会认为是页面中的一个元素.而在此出,iframe框架指向的页面即 src 代表是的 iframe 的一个属性,所以,这里应该把 iframe当成一个叶面元素,股应该用ID,改变src即可. Are you OK?
      

  9.   

    建议斑竹将此内容加入FAQ,因为iframe这个特殊的特性往往容易使人混淆,注意了!
      

  10.   

    谢谢楼上的兄弟,建议斑竹将此内容加入FAQ
      

  11.   

    正确的方法是:<iframe src="toppage.asp" name="ifrm" id="frm" width=100 height=100></iframe>
    <button onclick="document.ifrm.location.href="rightpage.asp";">改变框架页 </button>测试通过!现在我在对上面做一个解释!
      

  12.   

    有name属性的元素如下
    A, APPLET, attribute, BUTTON, EMBED, FORM, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, LINK, MAP, OBJECT, RT, RUBY, SELECT, TEXTAREA可以这么简单理解它们的使用区别:id用于DHTML,即客户端脚本。而name则通常用在服务器端,例如Request.form("")中就要用name。
    你用<input name=myinput id=myinput>中,在客户端
    <script>
    alert(myinput.value)//这里是id
    </script>
    而提交后,用Request.form("myinput"),这里就是name。
    id可以直接使用就得到对象,name的话一定要使用document.all.name来得到对象,现在提倡使用id,不过为了和以前兼容,可以两者都使用,而且名字也一样。上面的说法其实有点问题:只要把 docuent.ifrm 替换为 frm 一样可以可通过。为什么 改变src不行呢?因为 src只是一个客户端改变其属性,(就相当于 你动态改变一个 表格颜色),并不与服务器打交道,所以得不到你想要的结果。但是改变 location.href 就相当于刷新叶面的效果(相应服务器)。我们可以通过重新指定一个 叶面的 location.href 来达到刷新叶面并改变连接的效果。
    请看:<iframe src="toppage.asp" name="ifrm" id="frm" width=100 height=100></iframe>
    <button onclick="aa()">改变框架页 </button>
    <script>
    function aa(){
    frm.src="rightpage.asp";
    alert("你的框架页中的src已经改为"+frm.src+";但叶面没刷新,所以没有变化")
    }
    </script><iframe src="toppage.asp" name="ifrm" id="frm" width=100 height=100></iframe>
    <button onclick="document.ifrm.location.href="rightpage.asp";">改变框架页 </button>
    <iframe src="toppage.asp" name="ifrm" id="frm" width=100 height=100></iframe>
    <button onclick="document.ifrm.location.href="rightpage.asp";">改变框架页 </button>对frame 一样:请看例子:
    allpage.asp(包含框架页):
    <html><head>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head><frameset rows="64,*">
      <frame name="banner" scrolling="no" noresize target="contents" src="toppage.asp">
      <frameset cols="150,*">
        <frame name="contents" target="main" src="leftpage.asp">
        <frame name="main" src="rightpage.asp">
      </frameset>
      <noframes>
      <body>  <p>此网页使用了框架,但您的浏览器不支持框架。</p>  </body>
      </noframes>
    </frameset></html>toppage.asp:<html><head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>this is the top page</title>
    <base target="contents">
    </head><body><p>this is the top page</p>
    <button onclick="parent.contents.location.href='rightpage.asp'">改变左边窗口连接</button>
    </body></html>
    rightpage.asp:<html><head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>this is right page</title>
    </head><body><p>this is right page</p></body></html>
    leftpage.asp:<html><head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>this is the left page</title>
    <base target="main">
    </head><body><p>this is the left page</p></body></html>
    看看就知道了:
      

  13.   

    parent.HdMain.HdOaMainIf.document.location.href="test.asp"看看。HdOaMainIf 为 ID 是的写法。
    下面是 HdOaMainIf 为 name 时的写法:parent.HdMain.dicument.HdOaMainIf.document.location.href="test.asp"iframe 中的特殊情况 。
    iframeID.innerHTML 是没定义的。这是个奇怪的现象。在 InterDev 里面 ,iframeID. 可以感应出 innerHTML ,却感应不出document ,但前者无定义,后者却可以