最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to open a link in new tab using javascript - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question edited Aug 2, 2016 at 7:30 Vivek Jain 3,8896 gold badges32 silver badges47 bronze badges asked Apr 16, 2014 at 6:30 yashyash 8123 gold badges12 silver badges38 bronze badges 5
  • Here you go: stackoverflow.com/questions/16896284/opening-a-url-in-a-new-tab – mike00 Commented Apr 16, 2014 at 6:32
  • You need to set pop up property for the browser – Amit Commented Apr 16, 2014 at 6:32
  • @Rasher My code is working fine.But i want to open it into new tab, Not in new window – yash Commented Apr 16, 2014 at 6:34
  • forums.asp.net/t/… This can be useful – JoJo Commented Apr 16, 2014 at 6:37
  • possible duplicate of Open a URL in a new tab using JavaScript – StingyJack Commented Sep 15, 2015 at 16:40
Add a comment  | 

4 Answers 4

Reset to default 8
<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.

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 .

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;
});
发布评论

评论列表(0)

  1. 暂无评论