Search code examples
javascriptweb-standardsstandards-compliance

Mark some Javascript blocks as "special"


For some complicated reason, I need to mark some Javascript as "special", like this:

<script type="text/javascript" someattribute="special">
  var special = "I'm special!";
</script>

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

Is it possible to do this in way that complies with XHTML standards? According to http://www.w3schools.com/tags/tag_script.asp, all attributes for the script tag have very specific functions. But is there a workaround?

The idea is to pick up the tags as XML elements and put them in anther page, at server level, before it gets to the browser, so I need the special mark in the actual XML of the page. Adding it once the page has loaded, at browser level, using Javascript, will not work.

Any ideas?


Edit:

For the sake of standards-compliance, I can't use HTML5. The whole system I'm trying to be compliant with is XHTML 1.0.

Now that I've had time to think about it, I think that adding a GET variable or an anchor in the src of the script might just do the trick. For example, instead of the previous example, do

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

or

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

I'll try it now.


Solution

  • I'm looking back a this post a long time later. This is just to say that what I wrote in my edit did work and was standards-compliant.