Search code examples
javascriptbookmarklet

Bookmarklet - Add an input to middle of a URL?


This is probably extremely simple but I am a total newbie. I use something like this to add an input to the end of an URL

javascript:
(function() { 
    var val= prompt("Enter #",""); 
    if (val) 
        location="http://www.test.com?param="+escape(val);
})()

But now I want to add something to the middle of another url like:

http://www.test.com/ENTERSOMETHINGHERE/html/stuff/

I have no clue what I am doing.


Solution

  • Just concatenate the strings together:

    javascript:
    (function() { 
        var val= prompt("Enter #",""); 
        if (val) 
            location="http://www.test.com/"+escape(val)+"/html/stuff";
    })()