Skip to content

How to stop listening or un register from a messagehook

Peter Krautzberger edited this page Dec 12, 2013 · 2 revisions

For example after doing something like

MathJax.Hub.Register.MessageHook("End Process", function (message) {
    alert("end process");
});

you might want to clear or remove this listener.


Unfortunately, there is no direct API for removing a registered message hook (yet). But you can do the following:

var myHook = MathJax.Hub.Register.MessageHook("End Process", function (message) {...});
...
MathJax.Hub.signal.hooks["End Process"].Remove(myHook);

though I don't recommend doing it within the hook function itself (as that may throw off the processing of the list of hooks). Probably could do

setTimeout(function () {MathJax.Hub.signal.hooks["End Process"].Remove(myHook)},0);

however.


See also https://github.com/mathjax/MathJax/issues/693

Clone this wiki locally