I want to change between two pages in html with javascript, but when I change with window.location, the code that is after this sentence continues executing.
You can't execute code in your own page after doing window.location = 'page.html';. Your page will be replaced by the new page and the code in the current page will no longer be there.
The only ways to execute some code after page.html is loaded into the current window are as follows:
page.html that monitors when it finishes loading and trigger your desired action from there.