# Javascript Hooks

To register javascript hooks, use the WPD.Hooks javascript object methods **addFilter** and **removeFilter**

```javascript
/**
 * Adds a callback function to a specific programmatically triggered tag (hook)
 *
 * @param tag - the hook name
 * @param callback - the callback function variable name
 * @param priority - (optional) default=10
 * @param scope - (optional) function scope. When a function is executed within an object scope, the object variable should be passed.
 */
WPD.Hooks.addFilter = function( tag, callback, priority, scope )

/**
 * Removes a callback function from a hook
 *
 * @param tag - the hook name
 * @param callback - the callback function variable
 */
WPD.Hooks.removeFilter= function( tag, callback )
```

### Usage

<pre class="language-javascript"><code class="lang-javascript">// It's best to hook to the load event to make sure WPD global is loaded
window.addEventListener("load", () => {
    // Add regular function
    let func1 = funtion(arg1, arg2) {
        return 'my value';
    }
    WPD.Hooks.addFilter('hook_name', func1);
    
    // Add an object method, with reference to "this" inside the method
    let myObject = {
        'myValue': 'my value',
        'myFunction': function(arg1, arg2) {
           return this.myValue;
        }
    };
    WPD.Hooks.addFilter('hook_name', myObject.myFunction, 10, myObject);
    
    // Anonymous function
    WPD.Hooks.addFilter('hook_name', function(arg1, arg2){
    	return 'my value';
    });
    
    // To remove all hooks
    WPD.Hooks.removeFilter('hook_name');
});
<strong>
</strong></code></pre>

### List of Hooks

* [asp\_redirect\_url](https://knowledgebase.ajaxsearchpro.com/hooks/javascript-hooks/asp_redirect_url)
* [asp\_search\_data](https://knowledgebase.ajaxsearchpro.com/hooks/javascript-hooks/asp_search_data)
* [asp\_live\_load\_html](https://knowledgebase.ajaxsearchpro.com/hooks/javascript-hooks/asp_live_load_html)
* [asp\_search\_html](https://knowledgebase.ajaxsearchpro.com/hooks/javascript-hooks/asp_search_html)
* [asp\_compact\_width](https://knowledgebase.ajaxsearchpro.com/hooks/javascript-hooks/asp_compact_width)
