Set the page number in Javascript

Is there any way I can set the starting page number via Javascript within the page?

I know adding ?p=x to the URL will change the starting page of results, but I want to set this myself in code.

I’m using URL rewrites - e.g. /brands/Sony/2 - where 2 represents the page number. I’ve been able to apply facet filters in code, but page number is something I’m struggling with.


1 Like

Hi @baz, welcome here! To further help you with this question I will need more details like what did you try that did not worked as for setting the page? Can you maybe start a small example that we can use together and iterate on to solve your issue? Thanks.

Hi vvo,

I haven’t really tried anything as I don’t know what to try. I don’t see any settings in the instantsearch documentation that would allow me to control the page number. I’ve tried to look through the instantsearch code to work out a way to override it but didn’t manage to find anything.


Try this:

var search = instantsearch({
  searchParameters: {
    page: 2

And let me know how it goes.

1 Like

This works! Too easy.

This doesn’t seem to be in the doco… or did I somehow miss it?

Awesome that this worked! We are working on docs where we guide users more easily towards that kind of actions or examples. Thanks for feedback!

No worries, thanks @vvo