Reputation: 2052
I'm using a asp.net hyperlink control to open a web URL when a user click the hyperlink.
What I want to do is, say user click the hyperlink, so it should open new tab (not a new window).
if the user clicks the link again, it should not open a different tab. It should redirect user to the same tab which opened last time.
Update: here i found
Popup = window.open(URL, "LoginWindow");
This will redirect user to same window when the link is clicked. I'm using this functionality in popup windows. This works perfectly fine with Chrome & Firefox but not in IE.
It always open a new window rather than redirecting to the already opened one. Any Idea to solve this?
Regards
Upvotes: 1
Views: 5796
Reputation: 11
You can also try target="MyWindow" so it always open in this new window/tab. This way we can avoid opening new window/tab for every anchor link we click on.
Upvotes: 1
Reputation: 404
Try this code.Hope this will work for you
if (ViewState["hasvalue"].ToString() == "Clicked")
{
HtmlPage.Window.Navigate(new Uri("form2.aspx"), "_self");
}
else // First Time it will be opened in New TAB
{
Hyperlink1.target="_blank";
Hyperlink1.NavigateUrl="form2.aspx";
}
// Assign this value to session
ViewState["hasvalue"] = "Clicked";
}
Upvotes: 0
Reputation: 404
int i=1;
if(i==1)
{
Hyperlink1.target="_blank";
}
else
{
Hyperlink1.target="_self";
}
Upvotes: 0
Reputation: 1206
After opening in a new tab (new tab vs new window is a browser option, not an HTML option, see Open link in new tab or window) with
target="_blank"
you need to set the hyperlink target to self either when generating your the page in c# or in JavaScript
target="_self"
See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.target.aspx
Upvotes: 0
Reputation: 309
The attribute target="_blank" is your only option. Much will depend on users' browser specific settings, you cannot change. In modern browsers this will open a new tab, in others a new window.
Upvotes: 0