Mobile app version of vmapp.org
Login or Join
Frith620

: No Obvious Answer - Query-Strings and Javascript Say I have this main page /my-site/all-my-bath-soaps which lists all my products. It has a search filter text box that uses javascript to filter

@Frith620

Posted in: #Url

Say I have this main page /my-site/all-my-bath-soaps which lists all my products.

It has a search filter text box that uses javascript to filter the products they want to see on that page (the URL doesn't change as they filter).

Now from many other parts of the site I want to navigate to this products-page and see specific products. E.g.

<a href="/my-site/all-my-bath-soaps?filter='Nivea-Soap'">


will go to /all-my-bath-soaps and apply javascript filtering to see just that product and hide all dom nodes for the other products.

The problem is if the user changes the text in the filter from 'Nivea-Soap' to 'Lynx' the javascript will work fine and show the new products but the URL stays at ?filter='Nivea-Soap'.

Is there anything I can do about this? Of course, I don't want to reload the page with a new query string every time they change the search criteria. Somehow it'd be great to move the ?filter=... criteria into POST data instead - but how can I do this with a link I don't know...

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Frith620

1 Comments

Sorted by latest first Latest Oldest Best

 

@Odierno851

As far as I know you cannot change the URL path with javascript; this is primarily for security reasons. However you can change the hash. It is probably possible to change your javascript to work with #Nivea -Soap instead of ?filter=Nivea-Soap, although that would be a coding issue outside the scope of this stackexchange.

Note however that this solution would be even worse for SEO than your current solution. If you would like people to be able to find your products directly from search results you should consider giving unique URLs to the product pages even if it means reloading the page for them, though you could continue to use javascript solutions for search result filtering.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme