简体   繁体   中英

how i open this link in new tab?

 function myFunction() { var x = document.getElementById("frm1"); var text = ""; var i; for (i = 0; i < x.length;i++) { text += x.elements[i].value; } document.getElementById("demo").innerHTML = text; }
 .center { margin: auto; width: 60%; border: 3px solid #003fff; padding: 10px; text-align: center; }
 <div class="center"> <h3>go to city</h3> <form id="frm1"> link: <input type="text" name="fname" value=https://it.wikipedia.org/wiki/><br><br> City: <select name="lname"> <option value="roma">Rome</option> <option value="miami">Miami</option> </select><br><br> </form> <p>choose your city.</p> <button onclick="myFunction()">open</button> <p id="demo"></p> </div>


<html>

<head>

<style>

.center {

  margin: auto;

  width: 60%;

  border: 3px solid #003fff;

  padding: 10px;

  text-align: center;

}

</style>

</head>

<body>

<div class="center">

<h3>go to city</h3>

 

<form id="frm1">

  First name: <input type="text" name="fname" value=https://it.wikipedia.org/><br><br>

  City: <select name="lname">

  <option value="Milano">Milano</option>

  <option value="Firenze">Firenze</option>

</select><br><br>

 

</form>

 <p>choose your city .</p>

<button onclick="myFunction()">open</button>

<a href id="demo"></a>

</div>
`
<script>

function myFunction() {

  var x = document.getElementById("frm1");

  var text = "";

  var i;

  for (i = 0; i < x.length ;i++) {

    text += x.elements[i].value;

  }

  document.getElementById("demo").innerHTML = text;

}

</script>
`
 

</body>

</html>

Use this line in myfunction()

window.open(text, "_blank");

Sometime this change not work on some browser then use this

window.open(text, "_blank").focus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM