How to execute a script on JS when navigating to a new page?

C use the following code to turn on the link in the browser
(function() {
return location.href = 'some url';
}());


And I want to execute a script at a new address. Is this possible?
Tried window.onload and promise. Did not help
July 9th 19 at 10:25
2 answers
July 9th 19 at 10:27
If the page where you go not under your control, of course, impossible.
July 9th 19 at 10:29
If the domain is someone else's - it was only through injection/superstructure/private browser, for example, using GreaseMonkey.

If Your domain:
1. you can pass in GET parameters (or using the anchor link #) flag to activate a script
2. use LocalStorage
3. to use the installation of cookies
4. to use a preset flag in a server session via ajax before moving on.
The same question as the author. Need when you click the link to follow it to the right block and to it add the class using toggleClass.
How to do it? - Kian98 commented on July 9th 19 at 10:32

Find more questions by tags JavaScript