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.
M
You can use:
window.open(url,'_target')
_target
opens the page in next tab.
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/
<a href="javascript:" onclick="window.open('https://www.google.co.in');" target="_blank">Sample Code</a>
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;
});