Jump to content

help with URL param change


Macrura
 Share

Recommended Posts

Hi,

I'm trying to finish a new PW site, and there's one last thing i'm trying to achieve;

with this site, there are products where the product variants are child pages of the 'master product';

when a search returns a product variant, it has a querystring at the end that has the part #, like ?part=0001

the link takes them to the (master) product page, with that variant's specs highlighted (clientside using js), and an accordion open with the add to cart button for that variant.

I'm trying to get it so that if the user clicks on a different variant (on the accordion), the querystring changes (to like ?part=0002) to reflect the newly chosen variant, (and then the js to highlight the specs also triggers).

I've read 10 -20 solutions on stack exchange, and tried some jquery plugins, but i can't seem to figure this out... seems there should be an easy way to do it.. I looked at BBQ, which is probably what i need to use, but haven't quite got a solution yet... thought i'd run it by some of you fine folks here...

TIA

Link to comment
Share on other sites

One way would be to link to that new url. I'm assuming that you don't want that, and want to change it dinamically with js, but in that case I don't understand why you need that "part" query string, since you could simply highlight the new variant without making a server call... or maybe you need some info from the server to get the info of that variant, but for that you could call that variant page alone. But I may be far from understanding what you want to do.

Link to comment
Share on other sites

You could use hashs

//set
window.location.hash = someid;
// get
hash = window.location.hash;

and use 

$(window).on("hashchange", function(e){
    var hash = window.location.hash;
    // do what you need
});

BBQ might a little overkill for your needs, but you could use the simple hashchange implementation plugin of it.

  • Like 1
Link to comment
Share on other sites

@diogo - i'm trying to use only 1 page per product; the variants of the product are basically size, so if we show all 5 size variants on the page, it's easier to make a comparison... just re-read your post, i was originally doing it with the get variable and having the server render the page based on that, but then i decided that was bad since i want to pro-cache the site, so i switched it to clientside, using js; but now i realize i also should have changed this to use a hash instead of the querystring;

@soma - thanks - you also made me realize that i don't need to do this with a ?part=### querystring; i could just use a hash instead, like /#0001 ; i'm going to recode the links from the product search and the js to do the classes and then see if i can use the hash change...

update - this has all been sorted... thanks soma & diogo; working well now, i'll post site url soon in showcase.

Link to comment
Share on other sites

 Share

×
×
  • Create New...