0

Hi

I am looking to create a personalised web page, based on the web address I am going to give somebody. So say I have the web address beanburger.co.uk and was going to send you an email and your name was barbara I would give you the url beanburger.co.uk?name=Barbara (or something like that). Could someone help me with the code that would bring the name from the url and put it into the pages so that when you went to it the page might say "Hey Barbara".

Thanks

3
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by stbuchok
0
function getParam(paramName) {
    var url = window.location;
    var params = url.substring(url.indexOf("?") + 1 , url.length).split("&");
    for(var i = 0; i < params.length; i++) {
        var param = params[i].split("=");
        if(param[0] == paramName) return param[1];
    }

    return null;
}

var userName = getParam("name");

$("#welcome").html("Hey " + userName);

Hope this will work :)

Thanks!

0

Please note that Luckychaps answer requires jQuery.

line 14 can be replaced with:

document.getElementById('welcome').innerHTML = userName;

wlecome is the id of a div or other element on the page.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.