Button open link and execute code

Hello Community,
I’m trying to make a button open a url in another page (done with standard config)
AND execute some simple code (i.e. change the text into a textbox)
The problem is that when I put some code in onClick event the button stops working as expected, it doesn’t open the new page anymore, it only execute the event code.
How can I have both behaviours?
thanks

You can use wix-location.to() to perform your own redirection after your code runs.

can wix-location.to() open another page? ( target _blank )