Reputation: 333
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 click on the new image, its link replaces the link in the same child window. However I want it to open the link in a completely new window. How can I make that possible please? (Preferably in the code behind Thank You)
This is the JavaScript code I am currently using:
Page.ClientScript.RegisterStartupScript(this.GetType(), "open", " window.open(" + site + ",'open_window','myWindow','width=300,height=300,0,status=1,');", true);
Upvotes: 1
Views: 2282
Reputation: 1389
If you specify "_blank" as a window's name, a new window will always be opened.
Upvotes: 2
Reputation: 28645
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');
Upvotes: 2
Reputation: 148524
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.
Upvotes: 1
Reputation: 33048
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.
Upvotes: 1