# 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](/hooks/javascript-hooks/asp_redirect_url.md)
* [asp\_search\_data](/hooks/javascript-hooks/asp_search_data.md)
* [asp\_live\_load\_html](/hooks/javascript-hooks/asp_live_load_html.md)
* [asp\_search\_html](/hooks/javascript-hooks/asp_search_html.md)
* [asp\_compact\_width](/hooks/javascript-hooks/asp_compact_width.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/hooks/javascript-hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
