11

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

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
yash
  • 812
  • 3
  • 12
  • 37
  • Here you go: http://stackoverflow.com/questions/16896284/opening-a-url-in-a-new-tab – mike00 Apr 16 '14 at 06:32
  • You need to set pop up property for the browser – Amit Apr 16 '14 at 06:32
  • @Rasher My code is working fine.But i want to open it into new tab, Not in new window – yash Apr 16 '14 at 06:34
  • http://forums.asp.net/t/1902352.aspx?How+to+open+a+page+in+new+tab+in+javascript+or+jquery+ This can be useful – JoJo Apr 16 '14 at 06:37
  • possible duplicate of [Open a URL in a new tab using JavaScript](http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript) – StingyJack Sep 15 '15 at 16:40

4 Answers4

8
<a href="javascript:" onclick="window.open('https://www.google.co.in');" target="_blank">Sample Code</a>
5

You can use:

window.open(url,'_target')

_target opens the page in next tab.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
CodeOptimizer
  • 96
  • 1
  • 6
2

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 .

0

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;
});
Community
  • 1
  • 1
Mohammed Safeer
  • 20,751
  • 8
  • 75
  • 78