views:

43

answers:

3

Hello,

I'm building a web app for Sign In / Registration etc, and do not want the page to have to refresh.

www.mysite.com

I know how to set a hash on the URL without refreshing the page:

location.hash

to give: www.mysite.com/#signin

But what I want: www.mysite.com/signin

Without the hash so it's SEO friendly. Also, once I set that. How in JavaScript can I read the first path after the / so I can detect SignIn, Register,AboutUs etc, and show the appropriate content?

Thanks!

A: 

You can't change the location via JS without forcing a page-load. Only the hash part can be changed without forcing a page load.

Jani Hartikainen
A: 
document.location = "signin";

This will refresh the page. There's no way around it without using an anchor (hash).

Then to read the page you're on:

var page = document.location;
var path = page.pathname;

if (path == "signin") {
    // do something
}
Josh Johnson
A: 

Assuming your "signin" content is truly on the same page then the hash has no advantage or disadvantage as the page will be crawled and indexed regardless of the URL format. See this SO Post.

Dustin Laine