I am working on a website, in which I have to open a url from backend. I am using c# now. My problem is that I want to open link in new tab instead of new window.
My code is here:-
string url = ppHref.ToString();
string newScript = "<script language='javascript'>window.open('" + ppHref.ToString() + "', '_blank');</script>";
ClientScript.RegisterStartupScript(this.GetType(),"OpenUrl", newScript);
Can Anybody tell me how to open this url in new tab. I don't like pop ups so I don't wanna use window.open()
. Please help me.
Thanks in Advance
You need to use the _blank value in the target attribute to open the linked URL in a new tab or window. If you want to open URL with JavaScript, the open() method of Window interface is the best option. The JavaScript window. open() method opens a new browser window.
You just need an anchor ( <a> ) element with three important attributes: The href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings.
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
<a href="javascript:" onclick="window.open('https://www.google.co.in');" target="_blank">Sample Code</a>
You can use:
window.open(url,'_target')
_target
opens the page in next tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With