472,950 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

How to load run JavaScript onload function after an Ajax onload function

Frinavale
9,735 Expert Mod 8TB
I have a slight problem with a Tab Control that I've developed for an application. Once sent to the browser it runs via JavaScript. The JavaScript is dynamically generated by my .NET code. Everything works fine.

I've recently been adding "animations" to my web application using Ajax.
The animation "Fades" the page in once it is finished loading (without this fading effect the page load is very choppy).

My Tab Control requires some "initializing" when the page is loaded (sets some <div>'s invisible so to show only the one selected). Without this "initializing" all of the <div>'s are displayed.

I've been using the following JavaScript to initialize my Tab Control:
Expand|Select|Wrap|Line Numbers
  1.  
  2.                     if(window.attachEvent)
  3.                     {
  4.                       window.attachEvent("onload" ,"InitializeTabControl");
  5.                     }
  6.                    else{
  7.                         window.addEventListener("load","InitializeTabControl", false);
  8.                     }
  9.  
The problem with this is that the JavaScript call too fast...the tab that should be set to Visible is set before the Ajax animation that fades the page into view happens.

I've attempted to modify the JavaScript responsible for initializing my Tab Control to be:
Expand|Select|Wrap|Line Numbers
  1.  
  2.                     if(document.attachEvent)
  3.                     {
  4.                       document.attachEvent("onload" ,"InitializeTabControl");
  5.                     }
  6.                    else{
  7.                         document.addEventListener("load","InitializeTabControl", false);
  8.                     }
  9.  
However, this does not appear to do anything.

Does anyone know how to set the JavaScript for the Tab Control to happen about the same time as the animation?

Is the document.addEventListen supposed to work the way I'm trying to use it?
(I'm probably not using it right...)

Thanks a lot for your help!
-Frinny
Oct 17 '07 #1
5 9137
pronerd
392 Expert 256MB
The problem with this is that the JavaScript call too fast...the tab that should be set to Visible is set before the Ajax animation that fades the page into view happens.

I've attempted to modify the JavaScript responsible for initializing my Tab Control to be:
Expand|Select|Wrap|Line Numbers
  1.  
  2.                     if(document.attachEvent)
  3.                     {
  4.                       document.attachEvent("onload" ,"InitializeTabControl");
  5.                     }
  6.                    else{
  7.                         document.addEventListener("load","InitializeTabControl", false);
  8.                     }
  9.  
It sounds like it is working exactly as it should assuming the there is a supported onload or load event for the window element in the browser you are using. My understanding was the the onload events where only supported for the body and frame elements in most browsers.

Anyway it sounds like it is working as it should. The onload event is triggering as soon as the page downloads the code. That executes the logic making the tab visible. While that is going on the AJAX logic fades the page in.

The best option to get the entire page to fade in at the same time in sync might be to have the server side logic set the tab visibility, so that every thing on the page is then faded in together.

Another option would be to add a call in the fade in logic to call tab init functions so the tab is made visible as soon as the page finishes fading in.
Oct 17 '07 #2
Frinavale
9,735 Expert Mod 8TB
Thanks for your prompt advice Pronerd!

It sounds like it is working exactly as it should assuming the there is a supported onload or load event for the window element in the browser you are using. My understanding was the the onload events where only supported for the body and frame elements in most browsers.
It isn't working as it should becuase there is a split second where the JavaScript makes my Tab visible when nothing else is being shown.

Then the Ajax animation runs, which sets everything back to invisible and then fades it in.......

It's really not nice at all. I need to find a way to figure out how to get the JavaScript to load either at the same time as the Ajax, or after.

Anyway it sounds like it is working as it should. The onload event is triggering as soon as the page downloads the code. That executes the logic making the tab visible. While that is going on the AJAX logic fades the page in.

The best option to get the entire page to fade in at the same time in sync might be to have the server side logic set the tab visibility, so that every thing on the page is then faded in together.
This can't be done Server Side...after Sever Side code is executed, the output is sent to the browser into the web page....that's when the JavaScript and Ajax take over. The Server Side code has nothing to do with the web page until a postback occurs.....



Another option would be to add a call in the fade in logic to call tab init functions so the tab is made visible as soon as the page finishes fading in.
I'm not sure how to do this since the Ajax animation is generated for me by the Ajax.NET tool kit and is not written into the browser (it's stored in some resource somewhere on the server...like an external JS file)
Oct 18 '07 #3
acoder
16,027 Expert Mod 8TB
Why not use CSS to set the default visibility status?
Oct 18 '07 #4
Frinavale
9,735 Expert Mod 8TB
Why not use CSS to set the default visibility status?
That's what I do.
Originally every thing's set to visible="hidden".
Then the JavaScript runs and makes the "selected tab" visible="visible" and then the animation runs...which sets the whole page (contents) to visible="hidden" and then fades it in to visible="visible".

The problem is that the JavaScript is executed before the Ajax.
I need it to execute after or during the Ajax.
Oct 18 '07 #5
acoder
16,027 Expert Mod 8TB
If you have no control over the Ajax code, how about you check a certain element's or elements' visibility every second or less using setInterval? Once that element is visible, that means its now ok to display the div.
Oct 18 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: sylcheung | last post by:
Hi, How can I be notified when the document load is complet in JavaScript? I am referring to the whold document load is complete, mean all images/external files/frame/iframes have been loaded. ...
1
by: mathewda | last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding me at the moment. I've wrote some code that will set up an XMLHttpRequest, it then makes a call to open and send and sets the...
5
by: amit | last post by:
Hello, the javascript I'm using is not embedded into HTML but included. When I looking at w3schools.com it uses examples with js embedded into html. Anyway, when I use: function load() {...
1
by: jianxin9 | last post by:
Hi, I have an ajax powered tabs box that has a javascript drop-down search menu in the first tab. When I click on another tab, and go back to the first tab I have to refresh the page to get the...
5
by: steve.chambers | last post by:
I'm sure this q must have been asked before but I'm really struggling to find the answer anywhere so have finally given up and will consult the usenet community - hopefully there's someone out...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
8
by: sneddo | last post by:
Ok I am trying to do the above, I have got a script that will restrict the length but it requires the user to enter the field and hit a key, before it will work. This would normaly be find, but...
5
by: =?Utf-8?B?TWF0Y29u?= | last post by:
Hello, I have a asp.net 2.0 (vb.net) page, which uses a master page, and there is a javascript function (myfunction) defined in the <headof that master page. Is there a way to run the function...
4
by: ameshkin | last post by:
Hi Everybody, I'm just now learning javascript and I'm using mootools. What I want to do is to dynamically load a php page into accordian panel 2, depending on which radio button is selected in...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.