how i open this link in new tab?

gian

function myFunction() {

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

  var text = "";

  var i;

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

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

  }
  
window.open(text, "_blank");
  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>
Pradeep Kumar

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();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related