how to not reload page after clicking the “ok” button on alert?

Is there a way to prevent the page from refreshing after clicking an alert message? I’m looking for a solution to handle actions internally without triggering a reload. Any suggestions or advice on avoiding this automatic refresh would be greatly appreciated.