1

I have an external JS file that I load into my HTML

<script type="text/javascript" src="../js/busy.js"></script>

The script file itself looks like this:

window.onload = setupFunc;

     function setupFunc() {
       document.getElementsByTagName('body')[0].onclick = clickFunc;
       hideBusysign();
         Wicket.Ajax.registerPreCallHandler(showBusysign);
         Wicket.Ajax.registerPostCallHandler(hideBusysign);
         Wicket.Ajax.registerFailureHandler(hideBusysign);
     }

     function hideBusysign() {
       document.getElementById('busy').style.display ='none';
     }

     function showBusysign() {
       document.getElementById('busy').style.display ='block';
     }

     function clickFunc(eventData) {
       var clickedElement = (window.event) ? event.srcElement : eventData.target;
       if (clickedElement.type.toUpperCase() == 'BUTTON' || clickedElement.type.toUpperCase() == 'SUBMIT') {
         showBusysign();
       }
     }

Basically, it shows a little busy indicator within my website.

I also have an onload function in my body tag, this is new and helps me focus on the username text field when the page loads.

<body lang="de" class="fade-in one" onLoad="document.forms.login.username.focus();">

However, since I added this last functionality, the busy indicator stopped working because it also uses the onload function. What can I do to make it work again?

2 Answers 2

3

it's not the most elegant way .. but it will work

<body lang="de" class="fade-in one" onLoad="document.forms.login.username.focus();setupFunc();">
Sign up to request clarification or add additional context in comments.

Comments

2

Remove your body onload tag and put:

<script type="text/javascript">
window.onload = function() {
    document.forms.login.username.focus();
    setupFunc();
};
</script>

After your external Javascript (make sure it's still in the <head> tag). That should change window.onLoad to your custom function, which does what you need and then calls setupFunc.

4 Comments

won't work as long as there is a onload attribute in the body tag :)
There's no need for an onload tag any more, that function does both things. Updated to make it clear
i know that there is no need for the body onload anymore :) but without your update, I bet he would have left it there.. in fact your solution is the same as mine.. but with more characters ;)
Thanks for your solution as well. Unfortunately I can only pick one answer.. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.