-1

I am using below code for loading another web page url through button. This code is working correctly. Please suggest if we can open that url in new tab using window.location.href only?.

HTML:

<button class="float-left submit-button" id="myButton" type="button" target="_blank">Submit</button>

JS:

document.getElementById("myButton").onclick = function ()
{
    var labelVal = $("#study").text().trim();
    window.location.href= "/oGPGWW4EPjrLZZbl0_/analysis?file=/";";                
};
René Höhle
  • 26,716
  • 22
  • 73
  • 82
JanakiRam
  • 7
  • 1
  • 1
  • 3
  • "_using window.location.href only_" Not possible, unless you already have a tab opened. – Teemu Aug 15 '18 at 11:08
  • https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript – Saiqul Haq Aug 15 '18 at 11:08
  • 2
    Instead of `location.href`, use `window.open(url)`. Try like that. – Vladimir Jovanović Aug 15 '18 at 11:08
  • You shouldn't need to use the `open` function if you're using proper markup. A link would work, or a form worth a submit button. – zzzzBov Aug 15 '18 at 11:11
  • @Teemu Yes, one tab is already opened. if we click on button , i need to open the new url in another tab using window.location.href – JanakiRam Aug 15 '18 at 11:27
  • But `window` in `window.location.href` refers to the window where the script is executed, instead of `window` you've to use a reference to that other tab. The question is like you'd ask how to hit nails to concrete with bare hands, who wouldn't answer "use a hammer instead" ... – Teemu Aug 15 '18 at 11:41

1 Answers1

0
function(){
var win = window.open(url, '_blank');
 win.focus();
}
M Usama Alvi
  • 187
  • 1
  • 15