The Vip The Vip - 2 months ago 10
HTML Question

How to redirect browser to the link present in a textarea?

I am a complete newbie to web development.So please forgive me if i am asking a silly question.

I want to create a tool that will add a prefix to link.

Actually I want to create a Text-box in which a link will be pasted and after pasting when I click Go Button the tool should add some prefix to the pasted link and then redirect browser to the new link (i.e. Pasted Link+Prefix Added) .

I somehow managed to write some code that will add prefix to the link pasted in the textbox. But i am unable to make the browser redirect to the new prefixed link.

I tried using " window.location.replace() " for the redirect but its not the solution. Please help me.

<script>
function addtext() {
var newtext = "SOME-PREFIX";
document.myform.outputtext.value += newtext;
}
</script>

<form name="myform">
<textarea name="outputtext" rows="6" column="3"></textarea><br>
<input type="button" value="GO" onClick="addtext();"></p>
</form>

Answer

Something like that?:

function addtext() {
  var newtext = "SOME-PREFIX";
  window.location = document.querySelector("textarea").value + newtext;
}
<form name="myform">
  <textarea name="outputtext" rows="6" column="3"></textarea>
  <br>
  <input type="button" value="GO" onClick="addtext();">
  </p>
</form>

Comments