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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
<a href="javascript:" rel="nofollow noreferrer noopener" onclick="window.open('https://www.google.co.in');" target="_blank">Sample Code</a>
Method 2
You can use:
window.open(url,'_target')
_target opens the page in next tab.
Method 3
Html Code :
<button onclick="OpenInNewTab();" type="submit">
Javascript Code :
function OpenInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
Change Your Browser Setting.
In FireFox ,
Go To Options -> Tab setting and Check “Open New Windows in a New Tab instead” setting.
This Solution Worked For me .
Method 4
I think answer to this question will help , Open a URL in a new tab using JavaScript https://stackoverflow.com/a/30512485/2293686
try like this,
$('#myButton').click(function () {
var redirectWindow = window.open('url', '_blank');
redirectWindow.location;
});
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0