Forum Moderators: open

Message Too Old, No Replies

The "for" and "event" attributes in the <script> tag

How do you avoid using them?

         

Lindsey Kuper

2:45 pm on Aug 30, 2004 (gmt 0)

10+ Year Member



I have a couple pieces of code similar to this for a video player site I'm working on:


<script for="MediaPlayer" event="Buffering(bStart)" type="text/javascript">
progressText.innerHTML = "Loading...";
</script>

The "for" and "event" attributes are keeping my XHTML from validating. I'm quite new to JavaScript, but I'm sure there's a way to get rid of them and have that stuff within the script itself. I just don't know how to do it. Could someone show me how or point me to a reference? Thanks in advance.

Lindsey Kuper

2:57 pm on Aug 30, 2004 (gmt 0)

10+ Year Member



Okay, this [nexgenmedia.net] explains how to use event handlers in the standards-compliant way, but apparently IE doesn't support that at all. I can't have IE completely unsupported. Has anyone had this problem before? How did you deal with it?

Bernard Marx

3:26 pm on Aug 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There didn't seem to be anybody at home with that link.

This could be a complicated issue. The form of event handler/script assignment you have quoted is definitely IE-only, as you know. It's rarely used outside MS demos and applications.

There are a number of ways of assigning event handlers to a particular function (not script block, as posted). The traditional is to use HTML event handlers. Trouble is that XHTML only validates particular events.

You could try assigning event handlers via Javascript, but you best wait until the page has downloaded, then, eg:

myElement.onclick = functionRef

..is one way.

What kind of syntax you use for your buffer event I don't know (it seems to have brackets in for a start). Also, when the page has downloaded, the buffering event may have already fired.

Unless there are other ideas around, I'd (shock, horror) not bother with validation with respect to that particular attribute. All you miss out on is the W3C badge (just my opinion).

Of course, non-IE browsers will execute that script block immediately, so if you're going cross-browser, something needs to be sorted out.

RonPK

5:10 pm on Aug 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A quick & dirty solution would be to put the script inside a so called conditional comment, which is only read by IE and fully ignored by the W3 validator.


<!--[if IE]>
<script for=... event=...>
// script here
</script>
<![endif]-->

Bernard Marx

5:30 pm on Aug 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Neat.