Working with DOM events

I've set up a listener function to listen for the 'qt=ended' DOM event that the Quick Time player sends out. The code I have to register the listener is:

function register_EndListener () {
		var obj = document.getElementById('Poets');
        if ( !obj )
            obj = document.getElementById('embedPoets');
        if ( obj ) {
        	if ( document.addEventListener )
            	obj.addEventListener('qt_ended', songFinished, false);
        	else
            // IE
	            obj.attachEvent('on' + 'qt_ended', songFinished);
    	}
}

Open in new window


This runs as part of window.onload.

This works but only after I click back on the page that has the above JavaScript.  It seems that somehow the page lost focus and the event will only be sent to a page that has focus. Actually, when the song starts, a page pops up showing the song words, and after the song finishes I can get the 'qt_ended' event delivered if I click in either the popup window or the main window behind the popup.  What I want is for the event to to be delivered to its handler without anyone having to click somewhere.

Thanks for any suggestions.

Steve
stevaAsked:
Who is Participating?
 
stevaAuthor Commented:
I solved t his myself by purchasing and using the Longtail JW player. It has all the events I needed and they were easy to work with to get the music synchronized with the words..
0
 
Gurvinder Pal SinghCommented:
was the 'Poets' element loaded before document load or after document load?
0
 
stevaAuthor Commented:
Not sure.  The body contains a call to Apple's QT_WriteOBJECT Javascript routine,  which modifies the DOM to put in the proper <object>/<embed> tags given the parameters specified:  

 
<div id="player">
		<script language="javascript" type="text/javascript">
    
        QT_WriteOBJECT('GoGentle_1_256kbs.mp3' , '100', '15', '', 'AUTOPLAY', 'True', 'CONTROLLER', 'True', 'postdomevents', 'True', 'PLUGINSPAGE', 'http://www.apple.com/quicktime/', 
            'EnableJavaScript', 'True', 'emb#NAME' , 'Poets' , 'obj#id' , 'Poets', 'embed#id', 'embedPoets');

		</script>
	</div>

Open in new window


I don't know if the JavaScript runs when it's encountered or waits for the whole document to load, or not.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Gurvinder Pal SinghCommented:
this doesn't necessarily runs after the document has loaded.
May be, you can run a timer event periodically to check if this is loaded and then register the event handler
0
 
stevaAuthor Commented:
So you think that maybe the Poets element doesn't exist yet when I register the handler, so the handler doesn't get registered?  But then why does the event come through and get handled when I click in the popup or the main widow?
0
 
Gurvinder Pal SinghCommented:
<<So you think that maybe the Poets element doesn't exist yet when I register the handler, so the handler doesn't get registered? >>
Yes, it seems to be the case.


<<But then why does the event come through and get handled when I click in the popup or the main widow?>>
Because by the time you click, it poet element is ready
0
 
stevaAuthor Commented:
So the registration code suspends itself until the click to bring focus back makes it retry?

I could put the actual object/embed code in the HTML, instead of letting QT_WriteOBJECT() put it in, and then we'd know that Poets was there when the registration code ran at document ready.

0
 
Gurvinder Pal SinghCommented:
<<So the registration code suspends itself until the click to bring focus back makes it retry?>>
No, it doesn't wait for the document ready to happen before embedding the code. It just runs as a parallel thread.
0
 
stevaAuthor Commented:
I put the full object/embed code into the HTML, instead of letting QT_WriteOBJECT() do it, but the results are the same.  The qt_ended event doesn't get delivered until I click in the lyrics popup or the background. With the Poets element certainly existing now when the registration function runs at document ready, it seems certain that the registration is occurring correctly, yet the event still isn't delivered after it fires at the end of the song,  until I click something.

0
 
stevaAuthor Commented:
Sorry for not giving out the points but I had to solve this myself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.