views:

54

answers:

1

Hey,

I've coded an HTML page using jQuery for loading content. Now if I want to link directly to a submenu, is this possible to do with JavaScript?

So for example if someone goes to www.mydomain.com/submenu1/ then some JavaScript code will execute and load the needed contents?

Thanks a lot :)

Is it possible to realize that with htaccess?

+1  A: 

You will more likely want to have a URL structure that only needs a page to load from the server once, then the server is only queried by JavaScript XMLHttpRequests. Loading content based on a "hard" URL would be pointless, since you're doing a server request anyways and might as well return the content in the response.

For keeping addresses unique while still keeping the "hard" URL the same (preventing multiple server requests), you can use the hash/anchor part of the URL. This means your address might look something like this: http://www.example.com/#/submenu1/

The #/submenu1/ part stays on the client, so only / on www.example.com is requested. Then it's up to your JavaScript to load the content relevant to /submenu1/. See a page of mine for an example of this: http://blixt.org/js#project/hash?view=code

Also have a look at this question: http://stackoverflow.com/questions/1078501/keeping-history-of-hash-anchor-changes-in-javascript

Blixt
thank you, i'm goint to read trough it!
johnlikesit
i'm not really getting into it. could you please explain me how to include that into another page?
johnlikesit