I'm embedding a Windows Media Player control in an HTML page.
<object width="720"
height="480"
id="Player"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<!-- <param> tags left out -->
</object>
To subscribe to events from the control (e.g. PlayStateChange(newState)
), I have to add a <script>
tag, like the following:
<script language="JScript" for="Player" event="PlayStateChange(newState)">
var newStateText = document.createTextNode('' + newState);
var playStateContainer = document.getElementById('PlayState');
while (playStateContainer.firstChild) {
playStateContainer.removeChild(playStateContainer.firstChild);
}
playStateContainer.appendChild(newStateText);
</script>
Isn't there a way to subscribe to these event through plain JavaScript (without the extra <script>
tag for every event I'm interested in on every single instance of the control)?
With 5 instances of the control and 5 events I want too subscribe to, this would be 25 script tags. Furthermore, the control is wrapped in some library code in an external JavaScript file. The event handling code should be there too, and not in the HTML of the client application.