Open Appended URL in New Tab

I am working on a hub that allows me to put in a ticket number which is then appended to a URL so it opens directly in a ticketing system. I have this working. The final step is to have the ticketing system open in a separate tab.

Code

<form id="srs">
    <input id="srbcp" name="srbcp" type="text">
    <input type="button" onclick="pullsr('window.open')" value="Submit">
</form>


<script>

}

function pullsr() {

  var action_src = $("#srbcp").val();
  var srs = $("#srs");
  var urlLink = "https://xxxxxxx.com/SR/";
  var urlLink = urlLink + action_src;
  console.log(urlLink);
  location.href = urlLink;

 }

 </script>

2 answers

  • answered 2019-10-15 14:38 lalit mittal

    replace

    location.href = urlLink;
    

    to

    var win = window.open(urlLink, '_blank');
    win.focus();
    

    Hope it works for you.

  • answered 2019-10-15 14:38 chintuyadavsara

    You can do it by using window.open

    Below is the code

    <script src="https://code.jquery.com/jquery-3.1.0.js"></script><form id="srs">
        <input id="srbcp" name="srbcp" type="text">
        <input type="button" onclick="pullsr()" value="Submit">
    </form>
    
    
    <script>
    
    function pullsr() {
    
      var action_src = $("#srbcp").val();
      var srs = $("#srs");
      var urlLink = "https://xxxxxxx.com/SR/";
      var urlLink = urlLink + action_src;
      console.log(urlLink);
      //location.href = urlLink;
      window.open(urlLink, "_blank");
    
     }
    
     </script>