Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

In my project I wanted to open a new tab on button click.When I click on button second time I need to check if tab is already opened or not.If already opened then focus on that tab else open new tab.

What I have tried:

Below is code snippet which I wrote  on button click;

<pre>  string TabName = "TestTab";
            string url = txturl.Text;
            string script = string.Format("window.open('{0}','{1}');", url, TabName);

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"newPage"+UniqueID,script,true);


url : URL which is to be opened in the new tab.
TabName : Setting tab name(purposely)

I tried above code but when I click on button first time it is opening new tab with the tabname but when I click on second time I am passing blank URL with same tabname to focus on that tab.But its not working.

One more thin I noticed is that when I tried in browser console to focus on opened tab with tab name e.g : Tabname.focus it is working. but from code behind it is not.
am I doing something wrong?
Thank you in advanced.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900