onClick, Link to another page, then run page code

Could someone please help me correct the code below?

I’m in the process of creating a mega menu with buttons that navigate to pages with elements that need to expand.

Thanks in advance.

$w.onReady(function(){
$w(‘#QMS0button’).onClick(function(){
wixLocation.to(“/quality”)
.then(() => {
$w(“#Option1”).scrollTo();
$w(“#topicBox1”).expand();
});
})})

You can’t do it because the code runs on the current page and not on the next page.

You can do something like this:
Page1:

$w.onReady(function(){
	$w('#QMS0button').onClick(function(){
		wixLocation.to("/quality#Option1"); 
})
})

Page2:

$w.onReady(() => $w("#topicBox1").expand());

Thanks J.D,

This does the trick!