Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

    xbrowser innerHTML issues

    Hola folks, can anyone over look this sample code and explain why it works in IE/opera, but fails in NN, and FireFox? I can't seem to figure it out.

    Code:
    <script>
    function show(layer, content){
    if(layer){
    
    if(content){
    closeButton = 
    
    "%3CBR%3E%3CBR%3E%3Ca%20href%3D%22javascript%3Ashow%28%27"+layer+"%27%2C%20%27%27%29%3B%22%3Eclose%3C/a%3E";
    
    fullContent = unescape(content)+unescape(closeButton)+"<BR>----<BR>";
    }else{
    closeButton = "";
    fullContent = "";
    }
    
    if(document.layers){
     //NN4
    document.layers[layer].document.open();
    document.layers[layer].document.write(fullContent);
    document.layers[layer].document.close();
    return;
    }
    
     if(document.all){
    //IE
    document.all[layer].innerHTML = fullContent;
    return;
    }
    
    if(!document.all && document.getElementById){
    //NN6
    document.getElementById(content).innerHTML = fullContent;
    
    return;
    } } }
    
    </script>
    
    <a href="javascript:show('test', 
    
    '%3CTable%20bgcolor%3D%22red%22%20border%3D%2210%22%20height%3D%2250%22%20width%3D%2280%25%22%3E%3CTR%3E%3CTD%20bgcolor%3D%22white%22%3ETEST%20TEST%20TEST%20%2C%20NOTHING%20SPECIAL%20IN%20HERE...%3CBR%3E%3CBR%3E%3CBR%3Etest%20test%20test...%3C/tr%3E%3C/td%3E%3C/table%3E')">show</a>
    <BR>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam 
    erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut aliquip ex ea commodo 
    consequat. Duis autem veleum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel willum lunombro dolore eu 
    feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te 
    feugait nulla facilisi. 
    <Br>
    <div id="test">
    </div>
    <br>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam 
    erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut aliquip ex ea commodo 
    consequat. Duis autem veleum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel willum lunombro dolore eu 
    feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te 
    feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet 
    dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut 
    aliquip ex ea commodo consequat. Duis autem veleum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel willum 
    lunombro dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit 
    augue duis dolore te feugait nulla facilisi.
    Thanks for the help!
    [note: l'm not sure if whitespace got added in when i cut and pasted this, but l can assure you there's no whitespace on the actual page l'm working with locally]

    S. Gram

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    found the issue:

    if(!document.all && document.getElementById){
    //NN6
    document.getElementById(content).innerHTML = fullContent;
    return;

    shoul've been:

    if(!document.all && document.getElementById){
    //NN6
    document.getElementById(layer).innerHTML = fullContent;
    return;


    thanks anywho..

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    to speed a little bit the code (and for obvious logical reasons, as the NS4 and IE4 are used very little these times) I guess that you should have the order of the conditions like this:

    if(document.getElementById){//all the modern compliant DOM browsers, including NS6+, IE5+, Opera, Safari, Mozilla....
    ...
    }
    else if(document.layers){//NS4 only
    ...
    }
    else if(document.all){//IE4 only
    ...
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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