Recursive call to Window.open in Javascript.

Go To StackoverFlow.com

1

This is my Html.I need to open (same page)Page1.html in a new window, when I clicks in Page1.html.(First window) So I used window.open() for acheving this.Its works and produces Second Window But I also need to open same page(Page1.html) from the second window which was created from the First Window. So I used window.open() it is loading the Page1.html in the same window. It won't create any other new windows. In practical scenario, I need to create a new window with B.html from A.html. Also from Second Window (B.html) I need to create another window with C.html. Currently B will open, but C will not create any new window, It simply loads C.html in second window which replaces B.html

  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            function ShowPage(pageName) {
                window.open(pageName, null, 'height=400,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes');
            }
        </script>
        <a id="page1.htm" onclick="ShowPage(this.id);">Click Me</a>
    </body>
    </html>
2012-04-04 05:51
by kbvishnu


4

Have a new name for every window you open, because once a "named" window is already open, any window.open that uses that same name opens the content in that same window.

OR

set the name to "_blank" to open to a new window every time.

the name of the window can be set via the second parameter (instead of null).


According to this MDN article

If a window with the name strWindowName already exists, then strUrl is loaded into the existing window. In this case the return value of the method is the existing window and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location. To open a new window on every call of window.open(), use the special value _blank for strWindowName.

2012-04-04 05:56
by Joseph
Thanks it works : - kbvishnu 2012-04-04 05:58


1

Try using '_blank' instead of null in the second argument of window.open()

2012-04-04 05:59
by mim
Ads