Category: Code

  • BBC Homepage Beta Using jQuery

    The BBC Beta Homepage is using jQuery, but unfortunately it’s ugly.

    I should qualify that – I think it’s a good move to make the homepage more personalisable, but does it have to look so Web2.0?
    Big text was a fad a year ago, but it’s too informal for an internationally recognised and respected news source, and it makes it look so childish – I dread to think what the new CBBC sites would look like!

    I realise this is only a beta, and may well change considerably, but without a bit of a shrink I won’t be likely to use it as a homepage tab.

  • JavaScript Bug – Modulo of small numbers

    It seems that there is a problem with the modulo function, ‘%’, in JavaScript.

    For example: 10 % 0.1 should equate to zero but comes out as 0.09999999999999945 probably due to some internal floating-point rounding errors.

    Easy solution (a hack really): Multiply both numbers by 1000 before using the modulo function.

  • JS: Clear Default Value onFocus

    Simply add the following to the the onFocus attribute of any HTML form input tag.

    if (this.value == this.defaultValue) this.value = '';


    this.defaultValue is automatically given the value in the HTML.

  • Append to Body onLoad

    I looked for a long time how I could add JavaScript functions to an HTML document’s onLoad attribute.

    Eventually I found this, something so obvious that I had considered trying it but foolishly didn’t try.

    var oldLoad = window.onload;
    window.onload = function() {
      oldLoad();
      function2();
    }
  • jsReq

    I wanted to tell the user that they need JavaScript, but obviously only if they don’t already have it enabled.
    The following is a very crude script which uses the very fact that JS is available to hide the requirement notice…

    HTML:

    <!-- "jsReq" - Jez McKean (jazzle.co.uk) 2006-04-24 */ -->
    <div id="jsRequiredDiv" class="important"><span class="error">Warning!</span>
    You need to have javascript enabled to use this page.</div>

    JS:

    function removeElementById(eleId) {
    eleId = document.getElementById(eleId);
    if (eleId.parentNode && eleId.parentNode.removeChild) {
    eleId.parentNode.removeChild(eleId);
    }
    }
    removeElementById("jsRequiredDiv");