The URL is accessed by JavaScript

I have coded an HTML page using jQuery to load the content. Now if I want to link directly to a submenu, is it possible to do it with JavaScript?

So, for example, if someone goes to www.mydomain.com/submenu1/, will some JavaScript code execute and load the required content?

Many thanks:)

Is it possible to figure out what's with htaccess?

+2


source to share


1 answer


Most likely, you will want to create a URL structure that is only needed to load the page from the server once, and then the server only requests the JavaScript XMLHttpRequest

s. Loading content based on a "hard" URL would be pointless because you are still making a request to the server and may also return content in response.

To preserve unique addresses while keeping the "hard" URL the same (preventing multiple server requests), you can use a hash bind for the URL. This means that your address might look something like this: http://www.example.com/#/submenu1/



The part #/submenu1/

remains on the client, so only /

on is requested www.example.com

. Then, before your JavaScript, load the content related to /submenu1/

. See my page: http://blixt.org/js#project/hash?view=code

Also consider this question: Saving hash / anchor changes in JavaScript

+1


source







All Articles