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

Asked

Viewed 2,210 times

0

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

  • Instead of changing the question title, mark an answer as correct. This is not a forum.

  • From what you’re saying, it seems to be the case mark an answer as accepted. Here we do not write "solved" in the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.

  • Do not put solved in the title, the system has solved check itself, we are a Q&A, just mark the answer that solved the problem as correct.

  • 1

    Jeez, three-hit-combo.

  • 1

    @Renan and I always eat "Rubinho", always last.

  • Calm beasts... Sorry! Need all this not..

  • 1

    It was not on purpose Thiago, it was that everyone commented at the same time, but @Renan must be the Barry Allen, for a millionth of a second his comment came first.

  • I am not in the habit of using this site. When you see an error, just indicate it please! Unnecessary.

  • @Thiago was not on purpose, the people were just guiding you, no need to get upset, nobody is pulling your ear, they are only explaining you, there is nothing unnecessary.

  • "When you see an error, just indicate it please! " That’s what they did _(ツ)_/

Show 5 more comments

2 answers

1


You can use javascript with window.open or window.location to do as you wish.

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 of use:

 <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 typed in the text field with ID url, and opens a new tab or window with window.open.

0

Follow 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.