I want the below button code to open a new tab with the URLfetched from a js variable

can you please help me with the below query? I have a button code as shown below:

    <button type="button" onclick= "location.href=document.getElementById('Text1').value;return false;" class="btn btn-danger">Launch Console</button>

Here I have the URL value fetched from a javascript variable. Is there anyway I can open the same in a new tab ? Currently it's loading in the same window/tab.



You can do something like this :

function openInNewTab(url) {
  var win = window.open(url, '_blank');

<button type="button" onclick= "openInNewTab(urlHere)" class="btn btn-danger">Launch Console</button>
<input id=text type=text>
<button onClick="window.open(document.getElementById('text').value, '_blank');">URL In New Tab</button>

Just like I said, read the duplicate closely. And don't use location.href.



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.