Open script in the same window

Asked

Viewed 43 times

-3

I’m using a script to join strings and open a link, but it opens in a new tab. I need it to open in the same window.

<form>
<input name="url" type="text" id="cpf"> 
<input type="button" id="btn" value="Acessar" onClick="javascript: window.open('http://site.com.br/' + document.getElementById('cpf').value + '-2/');"
  • 6

    When using window.open you are explicitly saying to open a new window. Search how to do to redirect the user.

1 answer

3

To open in the same window the command would be:

<form>
<input name="url" type="text" id="cpf"> 
<input type="button" id="btn" value="Acessar" onClick="javascript: window.location.href = 'http://site.com.br/' + document.getElementById('cpf').value + '-2/';"

The window.open is used to create a new window, the window.location.href will indicate to the browser that the new address must be the parameter being informed.

May also be used window.location.assign(url), as listed below.

References: open window. : https://developer.mozilla.org/pt-PT/docs/Web/API/Window/open window.Location : https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Browser other questions tagged

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