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

Recommended Answers

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 …

Jump to Post

All 2 Replies

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!

Member Avatar

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.