简体   繁体   中英

How to open a page in new tab when user clicks ctrl key + link button?

I have this code which opens new page in different tab.

        protected void facebook_Click(object sender, ImageClickEventArgs e)
        {
            myurl = "http://www.facebook.com";
            string newWin = "window.open('" + myurl + "');";
            ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true);
        } 

But when i press ctrl key from key board and click link button then new tab is opened but in URL

javascript:__doPostBack('LinkButton2','') displays. and page is empty.

but i want to display facebook.com in new tab.

This might help you......In Page_Load event just add code

facebook.Attributes.Add("onclick", "window.open('http://www.facebook.com','List','width=600,height=500,status,resizable');return false;");

or just add facebook.Attributes.Add("onclick","window.open('http://www.facebook.com');");

I guess you are using server side control , that requires postback to get the target url or script.

Make anchor tag or any client side control , other code seems fine.

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