Question: I have the following HTML code : 

```
<div class="action-button">
    <a href="/wp-login.php?loginFacebook=1&amp;redirect=http://blabla.com" class="MyButton">Hello
    </a>
</div> 

```

Is it possible to call a javascript function (stored in a file) while redirecting instead of redirecting to a specific URL ?

The javascript file is in the same domain as the rest.

Thank you.

Answer: 
You can do it with a query string. for example

```
 <a href="http://blabla.com/mypage.html?callfunction=1">Hello</a>

```

then on the page it redirects to (mypage.html) you'd do something like

```
<script>
if (getParameterByName('callfunction') == 1)
    callMyFunction1();
</script>

```

You could also pass parameters via querystrings.

For more info on querystrings see--
[How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript)

```
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

```
Include the JavaScript upfront, then call the function from the submit handler