简体   繁体   中英

Window.open script manager is opening 2 pages

I have a btn_click event firing a method that should open the link but instead it opens 2 tabs: a duplicate of the open page and the desired link. this is in the btn_click .

Redirect_New_Tab("http://www.desiredlink.com");

and this is the method that it is calling.

private void Redirect_New_Tab(string url_To_Open)
{
    string modified_URL = "window.open('" + url_To_Open + "', '_blank');";
    ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", modified_URL, true);
}

and the resault of this method is that there are now 3 tabs open. 2 duplicates of the original aspx page and a tab with the opened link.

is there anything I'm doing wrong or can do differently?

Why not just call window.open straight from OnClientClick event?

<asp:Button ID="btn" runat="Server" OnClientClick="window.open('http://www.desiredlink.com')" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM