Embed link to search box redirect

Asked

Viewed 93 times

2

I have the link http://www.algumacoisa.com/d/ I need a code where there is a text box, the user type the link and click "go" then it is directed to

http://www.algumacoisa.com/d/HTTP://WWW.LINKDOUSUÁRIO.COM

Still no database, though. It is possible?

I couldn’t make it more specific because I couldn’t find anything similar or words to describe what I wanted.

  • Put the code to make it easy.

2 answers

2


From what I understand you need only concatenate the typed link + its url, I believe the javascript itself does this:

HTML:

<input type="text" id="link" />
<button id="ir" onclick="ir()">IR</button>

JS

function ir() {
 var link = document.getElementById('link').value;
 var url = "http://www.algumacoisa.com/d/";
 var linktodo = url+link;
 window.open(linktodo, '_blank');
}

It can be simpler using jQuery if use, if you do not want to open in another tab take the Blank. I hope I’ve helped.

2

Even though I already have a correct answer, I will post a suggestion with jQuery, as well as reminded his own friend who replied:

HTML:

<input type="text" id="link" />
<button id="ir">IR</button>

jQuery:

$(function(){
    $('#ir').click(function(){
        window.location.href = "http://www.algumacoisa.com/d/" + $('#link').val();
    });
});

Browser other questions tagged

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