URL parameters determine the URL load ()


I am building a jQuery based web app and I want to use URL parameters to navigate around it.

I would like to display content based on the URL parameter, with the 'load()' function getting the main body of the web page from an external URL and replacing an element with it.

How would I create an if statement that use the following conditions...

  • If there are no parameters in the url, then use $("#toBeReplaced").load("home.txt");

  • If the parameter page is equal to about, then use $("#toBeReplaced").load("about.txt");

  • If the parameter page is equal to contact, then use $("#toBeReplaced").load("contact.txt");

...to determine what page of the app to display.

You can simply load the url using page variable if it is undefined then load home otherwise load whatever is in page variable.

var page = location.search.substring(1).split('=')[1];
if (page == undefined)
  $("#toBeReplaced").load(page + ".txt");