Skip to content Skip to sidebar Skip to footer

What JavaScript Code Can I Use To Open In A New Window, And Not The Window I Previously Opened

I am new to JavaScript. Here is the scenario; I have an imagebutton that changes every 10 seconds and when I click it opens a link in a new window and when the image changes and I

Solution 1:

If you specify "_blank" as a window's name, a new window will always be opened.


Solution 2:

The 2nd parameter of window.open is the name of the window. In your code you are replacing the old window because you never change the name for the new windows.

 window.open(address1, 'window1', 'myWindow', 'width=300,height=300,0,status=1');
 window.open(address2, 'window2', 'myWindow', 'width=300,height=300,0,status=1');

Edit: As already mentioned, it would be easiest to use _blank as the 2nd paramter. _blank will always create a new window which will prevent you from having to change the window name for any additional windows.

window.open(address1, '_blank', 'myWindow', 'width=300,height=300,0,status=1');

Solution 3:

You'll have to give different names to the windows. Your's are always called the same:

 window.open(adress1, "NewWindow1", "width=300,height=400,left=100,top=200");
    window.open(adress2, "NewWindow2", "width=300,height=400,left=100,top=200");

Note that Opera will always reuse the first window.


Solution 4:

try this :

Page.ClientScript.RegisterStartupScript(this.GetType(), "open", " window.open(" + site + ",'open_window222','myWindow','width=300,height=300,0,status=1,');", true);

please notice open_window222

you must give different identifiers !

from MDN

If a window with the name strWindowName already exists, then strUrl is loaded into the existing window.


Post a Comment for "What JavaScript Code Can I Use To Open In A New Window, And Not The Window I Previously Opened"