How to open a link in new tab using javascript

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:

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

Have you try this code: Originally shared here

function OpenInNewTab(url )
{
  var win=window.open(url, '_blank');
  win.focus();
}

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers and the default "new window" behavior. You could do it this way or by adding an event listener to your DOM object.

<div onclick="OpenInNewTab('www.test.com');">Something To Click On</div>

Please also try this:

Add your form name attribute like:

<form name="form">

and then try it like that:

<a href="" onclick="window.open( form.url.value, 'windowName' ); return false" target="_blank">Submit</a>

and check this link http://jsfiddle.net/ef69K/

Answer

You can use:

window.open(url,'_target')

_target opens the page in next tab.

Answer

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 .

Answer

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;
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.