【转载】解决window.showModalDialog 模态窗口中location 打开新窗口问题

 

 在我们的项目中,通常会用到showModalDialog 打开一个模态的子窗口,但是在这个子窗口中js方法里的document.location="" 通常会打开一个新的窗口,不论你的如何设置,问题的根源据我所以可能是js中遗留的问题,那么在js中document.location 唯独就是打开一个新的页面,但是同时<a href=""  的打开方式确可以在原窗口中打开。那么我们可以利用js创建一个模拟的点击链接,例如:

function go(url) 
{       
    var   a=document.createElement("a");   
    a.href=url;   
    document.body.appendChild(a);   
    a.click();  

}

那么在使用document.location 时调用go(url),把你的请求做参数放入,无论是action,还是jsp都可以。

这样就就解决了模态中js调用location的问题了。





posted @ 2014-02-20 15:57  飞起航  阅读(4332)  评论(0编辑  收藏  举报