www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: Function Library

  1. #16
    Join Date
    May 2004
    Location
    FL
    Posts
    3,447
    Ah, read my mind. That's where I was going to point to. Thanks!

    I forgot this thread was here. Some good stuff to share with others.
    Lee

    ""Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."" -- Sir Winston Churchill

  2. #17
    Join Date
    Aug 2007
    Posts
    3,767
    I don't know if you want these types, but here are three that I use all the time.
    PHP Code:
    document.getElementsByClassName = function(className,tagName) {
        if (!
    document.getElementsByTagName) {
            return 
    false;
        }
        var 
    elements document.getElementsByTagName(tagName||"*");
        var 
    length elements.length;
        var 
    classElements = new Array();
        for (var 
    0lengthi++) {
            if (
    elements[i].className.match(className)) {
                
    classElements[classElements.length]=elements[i];
            }
        }
        return (
    classElements.length>0)?classElements:false;
    }
    window.addOnloadEvent = function(addToOnload) {
        var 
    oldOnload;
        if (
    window.onload) {
            
    oldOnload window.onload;
            
    window.onload = function(){
                
    oldOnload();
                
    addToOnload();
            };
        }
        else {
            
    window.onload addToOnload;
        }
    }
    window.addElementOnload = function(elementId,onloadFunction) {
        if (
    document.getElementById && document.getElementById(elementId) != null) {
            
    onloadFunction();
        }
        else {
            
    setTimeout("window.addElementOnload('"+elementId+"',"+onloadFunction+");",50);
        }


  3. #18
    Join Date
    Nov 2002
    Location
    England
    Posts
    693
    Short and simple script to replace the images on a web page with a text node containing their alternate text if images have been disabled.

    PHP Code:
    <script type="text/javascript">

    // Try to load a small image

    var testImage = new Image;
    testImage.src "testimage.jpg";

    onload = function(){

       if(!
    testImage.complete){

       
    // If the image has not loaded the user has disabled images in the browser
       // Find all of the images on the web page

       
    var documentImages document.getElementsByTagName("img");
       
         for(var 
    i=0i<documentImages.lengthi++){

         
    // Create and insert a text node after the image using the image's alternate text

         
    var replacementText document.createTextNode(documentImages[i].alt);
         
    documentImages[i].parentNode.insertBefore(replacementTextdocumentImages[i]);

         
    // Hide the image

         
    documentImages[i].style.display "none";

         }

       }

    }

    </script> 

  4. #19
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Quote Originally Posted by Scriptage
    Short and simple script to replace the images on a web page with a text node containing their alternate text if images have been disabled.
    That is what the alt attribute is for: http://www.cs.tut.fi/~jkorpela/html/alt.html
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #20
    Join Date
    Nov 2002
    Location
    England
    Posts
    693
    That is what the alt attribute is for: http://www.cs.tut.fi/~jkorpela/html/alt.html
    No it isn't. This replaces the image with a text node; run the code without the test image and you will see the distinct difference. You could also use the following code to degrade an image based menu into a completely text based menu.

    PHP Code:
    <script type="text/javascript"

    // Try to load a small image 

    var testImage = new Image
    testImage.src "testimage.jpg"

    onload = function(){ 

       if(!
    testImage.complete){ 

       
    // If the image has not loaded the user has disabled images in the browser 
       // Find all of the images on the web page 

       
    var documentImages document.getElementsByTagName("img"); 
        
         for(var 
    i=0i<documentImages.lengthi++){ 

         
    // Create and insert a text node after the image using the image's alternate text 

               
    if(documentImages[i].className == "menu"){
        
               var 
    replacementText document.createTextNode(documentImages[i].alt); 
               
    documentImages[i].parentNode.insertBefore(replacementTextdocumentImages[i]); 

               
    // Hide the image 

               
    documentImages[i].style.display "none"

            }

         } 

       } 



    </script> 

  6. #21
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    If images have been disabled the user will see the alt value, try it and see.
    Anyone with images disabled will almost certainly have JavaScript disabled.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #22
    Join Date
    Nov 2002
    Location
    England
    Posts
    693
    If images have been disabled the user will see the alt value, try it and see.
    Anyone with images disabled will almost certainly have JavaScript disabled.
    Yes I know they see the alt value but they also see a box around the image and a cross; I sometimes browse with Javascript enabled and images off, I'm sure other people do aswell, especially in low bandwidth environments; I would be interested in seeing any explicit proof that people with images disabled do not have Javascript enabled.

  8. #23
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Quote Originally Posted by Scriptage
    Yes I know they see the alt value but they also see a box around the image and a cross
    Only with IE and it indicates that there is more visual information.
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles