Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables to Javascript from "pretty" URL

My problem is, I would like to create "pretty" URLs for visitors that look like this:

http://domain.com/Name

I have users that often send friends to my service, and I have been created customized pages for each one with the person's First Name in the headline. E.g., "John, here's an easy way to fix this widget"

I then save the page as an index.html file in a custom folder so the link structure for the custom page is domain/Name with Name being their First Name.

This is getting tedious and I would love to use Javascript to automate the process. However, the only documentation I can find on passing variables to Javascript involves "ugly" domains such as domain/jspass2.html?FirstName=John&LastName=Smith

Is there a way to beautify these domains and still pass the variables to a javascript code that inputs their name into the html code? I don't want to "cloak" an ugly domain (using a href, for example)

Thanks for the help!

like image 570
user3931737 Avatar asked Nov 21 '22 16:11

user3931737


1 Answers

Well, you could make it "prettier" by making the querystring cleaner.

example:

http://www.domain.com/?John,Smith

The javascript in your index file can read that.

var getQueryString = function() {
    queryString = window.location.search;
    queryStringCleaned = queryString.substring(queryString.indexOf('?') + 1 );

    return queryStringCleaned;
};
like image 50
glowworms Avatar answered Dec 16 '22 12:12

glowworms