How to open a page according to the link inserted in the input?

0

I want to make a form that when I put the address (URL) in a field and click the Send button go to the site entered in the field. How to do this?

    
asked by anonymous 06.10.2017 / 17:15

2 answers

1

You can use javascript with window.open or window.location to do what you want.

Example with window.open ():

It will open the url in a new window.

window.open('http://www.google.com');

Example with window.location.href:

It will open in the current window

window.location.href = 'http://www.google.com';

Example usage:

 <form>
    <input name="url" type="text" id="url"> 
    <input type="button" id="btn" value="Acessar" onClick="javascript: window.open(document.getElementById('url').value);" />
 </form>

The javascript takes the link entered in the text field with id url, and opens a new tab or window with window.open .

    
06.10.2017 / 17:27
0

Here's an example

document.getElementById('send').onclick = function(){
  let url = document.getElementById("url").value
  alert(url)
  window.open(url, "_self")
}
<input type="text" id="url">

<button id="send">Enviar</button>
    
06.10.2017 / 17:20