A页面使用showModalDialog 函数弹出B页面,在B页面中,使用了按钮单击事件修改页面路径如:
<input type="button" value="切换地址" onclick="window.location.herf='C.aspx'"/> 切换到C页面但是这样的话,会弹出一个新窗体显示C页面,而不是当前页面显示。
加了<base target="_self">也没用,这个只能对超链接有效。如何解决???

解决方案 »

  1.   

    楼主在创建模态对话框时是不是忘了传递window参数?window.showModelessDialog("xxx.html",window);
      

  2.   

    A.html
    ----------------------------------
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function gotoModalDialog(url,w,h)
    {
    window.showModalDialog(url,"","dialogWidth="+w+"px; dialogHeight="+h+"px; resizable=yes;help=no;status=no;scroll=no");
    }
    </script>
    </head>
    <body>
    <p></p>
    <p>
      <input type="button" value="模态窗体B" onclick="gotoModalDialog('modal.html','500','300')"/>
    </p>
    </body>
    </html>B.html
    ----------------------------------------
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>B页面</title>
    </head>
    <body style="width:300px; height:300px">
    <p>
      <input type="button" value="关 闭" onclick="window.close()" />&nbsp;
      <input type="button" value="更改URL" onclick="window.location='C.html'" />&nbsp; <!--在新窗体打开了-->
      <a href="c.html">连接</a><!--链接则有效:在本窗体打开-->
    </p>
    </body>
    </html>C.html内容页<input type="button" value="更改URL" onclick="window.location='C.html'" />
    通过js控制的代码都会弹出新窗体,动态页面后台写代码也是,如asp.net的后台
    Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "<script>if(confirm('成功,即将关闭窗体')) window.close()");这句代码总是弹出新的窗体不会关闭页面。
      

  3.   

    你可以把这个按钮改成链接啊
    <input type="button" value="切换地址" onclick="window.location.herf='C.aspx'"/>
    改成
    <a href="" target="_self"></a>
      

  4.   

    由于其他原因,要使用js 的window.location.herf , 不用超链接
      

  5.   

    怎么防止showModalDialog 弹出新的窗体啊 ???
      

  6.   

    直接不用button用<a></a>
      

  7.   

    直接用<a></a>不用button.加上target="_self"
      

  8.   

    在b页面中添加form标签;点击按钮的时候submit下
      

  9.   

    问题解决:
    添加表单,form.action='url';form.submit() 代替 window.location='url'