• Open window HTML validator friendly

    Some time ago I found this script which enables you to open links in a new window. Typically links in html were something like this:

    Mike's Site = <a href="http://www.mikesite.me" target="_blank">Mike's Site</a>

    The instruction target=”_blank” was the one that make the link open in a new window. Now the W3C decided that you shouldn’t use that anymore. Browsers still support it, but if you want to html validate your site, that would throw you an error. So here is a little javascript function that fix that:

    function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName(“a”);
    for (var i=0; i var anchor = anchors[i];
    if (anchor.getAttribute(“href”) && anchor.getAttribute(“rel”) == “external”)
    anchor.target = “_blank”;
    }
    }

    Usage: simply put in your links the attribute rel=”external” and include that function and then call it after all the document have been loaded with something like:

    window.onload = externalLinks;

    Hope that would help you, contact me if you need further indications. I would love to help :) Me@mikesite.me

     
  • Multidimensional Arrays on JavaScript

    Here is the code:
    var myArray=MultiDimensionalArray(2,3);
    function MultiDimensionalArray(iRows,iCols)
    {
    var i; var j; var a = new Array(iRows);
    for (i=0; i < iRows; i++)
    {
    a[i] = new Array(iCols);
    for (j=0; j < iCols; j++)
    {
    a[i][j] = “”;
    }
    }
    return(a);
    }

    Now you can use myArray[0..1][0..2]