Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.50/5 (3 votes)
Hi
i have write following type of code for open new window using javascript

printURL= "abcd.aspx";
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", "<script>window.open('" + printURL + "', '', 'top=100,left=300,menubar=no,toolbar=no,location=no,resizable=no,height=600,width=850,status=no,scrollbars=yes,maximize=null,resizable=0,titlebar=no');</script>");


its working fine, its open when i am clicking on "window open button". but when i minimize the window and again click on "window open button" new window open in other window, i want to open new window on same window, please suggest me.

waiting for reply.
Posted

The answer is - You cannot...

This is because your parent page does not know about the new window opened on your previous click. There is no connection between these parent and child instances of the browser windows. So each time you click the link it will create a new instance of browser and as a result a new window everytime.
 
Share this answer
 
Check this out:
XML
<html>
<head>
<script type="text/javascript">
var theWin = null;
function open_win(url)
{
    if(theWin && theWin.location)
        theWin.location.href=url;
    else
        theWin = window.open(url,"TheWin",'top=100,left=300,menubar=no,toolbar=no,location=no,resizable=no,height=600,width=850,status=no,scrollbars=yes,maximize=null,resizable=0,titlebar=no');
    theWin.focus();
}
</script>
</head>
<body>

<a href="#" onclick="open_win('http://google.com')" />google</a>
<a href="#" onclick="open_win('http://yahoo.com')" />yahoo</a>

</body>
</html>


Note: with IE has some limitations (see: http://msdn.microsoft.com/en-us/library/ie/ms536651(v=vs.85).aspx[^])
 
Share this answer
 
v2
Comments
omprakash katre 25-Jul-12 1:41am    
Thanks for reply.
i have got the solution

C#
function openWindow(printURL) {
             var newWin = window.open(printURL, 'PrintABC', 'top=100,left=300,menubar=no,toolbar=no,location=no,resizable=no,height=600,width=850,status=no,scrollbars=yes,maximize=null,resizable=0,titlebar=no');
             if (newWin != null) {
                 newWin.focus();
                 void (0);
             }
          }
 
Share this answer
 
Comments
Zoltán Zörgő 25-Jul-12 7:01am    
I think I posted the solution hours before you did. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900