How to call jquery function with only url?

This is my first question. So here we go.

I have a website, 100% xhtml / css with some ajax features thanks to jquery.

te there is a problem .. for all the "subpages" .. url remains the same (index.php) ..

my question is:

Can jquery allow some URL parameters to run a specific function?

example: www.mypage.com β†’ home page .. if I click .. let's say products .. url will be the same .. and if I try to send the URL to a friend (copy and paste) it will be www.mypage.com. ... so if my friend clicks on the link, he will be redirected to the home page, not to the product page, which is the section I want to share with him.

anyway, to set the url as .. www.mypage.com?s=products to fire the jquery event without using php?

early.

+4
source share
5 answers

http://blog.rebeccamurphey.com/2007/12/04/anchor-based-url-navigation-with-jquery/

I have never done this, but this site has a fairly direct method.

Basically, you specify an anchor tag for each logical page and update the URL accordingly when the user navigates to that logical page.

When a new user arrives, you parse the query string (as mentioned above) and then perform the corresponding navigation action.

+2
source

jquery querystring plugin provides an easy way to parse query strings.

+2
source

It seems to me that you want to change the request without reloading the page. It's impossible. What you can do is change the part of the #anchor url, so your ajax links will set the location in mysite.com/#products and then use jquery to detect at boot time and act accordingly.

+2
source

Typically, fake pages in an AJAX application change the request with the addition of something after # , for example www.mypage.com/#products . If you try to change the URL to another URL in JavaScript, the browser will redirect it to this page. However, if the change occurs after # , it will remain on the page (and try to place an element with this ID at the top of the browser window).

So, you can try something like the following JavaScript to set the url:

 window.location.hash = 'products'; 

You can then find this when the page loads so that you know which page you need to get.

There are also many predefined JavaScript libraries that make sure that the story works correctly in these scenarios, although I don’t know enough to recommend a specific library.

+2
source

There are many plugins for this kind of function. The keyword to find them is "history"

+1
source

All Articles