I want to do the following in my script:

Declare 3 variables in one function and call this function on window load. After that use values of those 3 variables in my other functions. Any option to do this without having to declare those variables outside the function as globals?

Again, it is important that the variables are declared inside a function which will be called on page load.

HTML code:

<a href=''onclick='_default();return false;'>Link</a>
<div id='mydiv'></div>


function _default(){

var x = document.getElementById('mydiv');
var h = x.offsetHeight;




function _main(x,h) {



You will see that this script executes _default() on page load. _default() function passes 2 parameters to _main() and executes _main() function throwing 2 alerts with variables x and h. But how do I make it so that those 2 alerts are thrown when I click on the link (see html code above)?