简体   繁体   中英

Is there any Js event or function which fires or executes before any action?

由于AngularJs有一个指令onLocationChange()C#具有onActionExecute() ,因此在Javascript中是否有类似这样的事件在整个网站中的任何动作之前执行。

from your question it seems like you want to observe user navigation ie: when ever address bar location gets changed.

You can use an older method detecting whenever page gets refresh

window.addEventListener('beforeunload', function (e) {
    // perform  something here
}, false);

for SPAs (Single page applications you can use hashchange

//detecting hashchange
window.onhashchange = function() { 
     //code  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM