RE: Using DOM to replace media attribute in the link tag on page load

Patrick Garies:
| The original code was correct. |mediaType[x]| (not |mediaType.item[x]|) 
| is an ECMAScript alternative.
...
| That would be |getElementById| (with a lowercase ā€œdā€).

My apologies, thanks for the correction. I had tested before I wrote that, and it initially appeared that Jonathan's code didn't work, while mediaType[x] and getElementById("linkid") without the loop did work. But when I tested thusly:

<script type="text/javascript">
window.onload=function() {
  var mediaType = document.getElementsByTagName("link");
  for(var x=0; x<mediaType.length; x++) {
    mediaType.item(x).setAttribute("media", "all");
    alert(mediaType.item(x).getAttribute("media"));
  }
}
</script>

media type was changed in FF 3.01, Opera 9.51, and IE 5.01.

| * The MIME type text/javascript is deprecated in favor of the MIME types 
| application/javascript and application/ecmascript. Unfortunately, 
| neither are supported in Windows Internet Explorer up to version 7.

I'm still seeing a lot of pre-XP Windows with IE < 7 in my web server logs. It'll be a while before implementation of that change is a good idea.

Received on Tuesday, 22 July 2008 14:49:30 UTC