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?
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?
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
.
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>