If the new page is a page whose code you control, then you can pass a query parameter to the new page via the link and you can have the javascript in the new page check for that query parameter and, if found, run some code in the page upon page load.
<a href = "http://www.example.com/otherpage?runOnStartup=3">LINK DISPLAY NAME HERE</a>
And the startup javascript in the new page would check for the runOnStartup
query parameter and run some code based on its value.
If the new page is in the same origin as your current page, then you could open the new page in a new window and then after it opened, you could call a function in that new window. But, your previous page would have to still be running in order to do that.
If the new page is in a different origin and you do not control the code in that new page, then you cannot do what you're asking for browser security reasons.
Warning: Do not use the following code in any remotely-production related machine. It is trivially susceptible to XSS and allows anybody to run any JS code on your website. This means that a malicious website could trivially steal your users' identities and other sensitive data. I highly recommend I recommend against using the method described in this answer in any form/
<a href="mypage.html?javascript=URL_ENCODED_JAVASCRIPT_HERE"></a>
<script>
var javascript = <?=$_GET['javascript'] ?>;
eval(decodeURIComponent(javascript));
</script>
If you don't have PHP, use:
var javascript = window.location.href.match(/[^?=]+$/)[0];
*I haven't tested this code so it may need some fixing. I am also assuming you own both pages. If the target page isn't yours, you can't run JavaScript on it for security reasons.
to URL encode your JavaScript, go here, type your JavaScript, and hit encode.
This is possible, no problem.
Note that IE has weird incompatibilities in this area of the DOM.
<!DOCTYPE html>
<html>
<head></head>
<body>
<a id="foo" href>Click me!</a>
<script>
document.getElementById('foo').onclick = onFooClick;
function onFooClick(e) {
var scriptToInject, popUp, node, importedNode;
scriptToInject = 'document.body.innerHTML = "Hello from the injected script!";';
popUp = window.open('about:blank');
node = document.createElement('script');
node.textContent = scriptToInject;
importedNode = popUp.document.importNode(node, true);
popUp.document.body.appendChild(importedNode);
}
</script>
</body>
</html>
The above works in Chrome, Firefox and Safari on a Mac.