SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying netscape 4 Window width

    Hi,

    I have this piece of code which i hope will output some text depending on the innerwidth of the browser window.

    At the moment it works fine in IE, however in Ns 4 it disaplys nothing

    Code:
    <script language="javascript">
    
    var winW = 630, winH = 460;
    
    if (parseInt(navigator.appVersion)>3) {
    		
    	if (navigator.appName=="Netscape") {
      	winW = window.innerWidth;
    
      	if(winW<=680 && winW>=550){
    	winW = "420";
    	}
      
    	elseif(winW<=550 && winW>=520);{
    	winW = "450";
    	}
        
    	elseif(winW<=520 && winW>=490);{
    	winW = "480";  
    	}
    
    	elseif(winW<=490);{
    	winW = "510";
    	}
    
    	}
     	else {
      	winW = "700";
     	}
     	
     	}
    
    document.write('<div id="Layer1" style="position:absolute;
     width:200px; height:115px; z-index:1; left: 38px; top:' + winW + '">tretet</div>');
    
    </script>
    Hoping some1 can tell me what im doing wrong, cause i new to this javascript stuff.

    Thnx
    Last edited by redgoals; Dec 9, 2002 at 16:07.
    http://redgoals.com ... my site ... nuff said

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi redgoals,

    I notice 3 things in your code...

    1. "elseif" should be "else if"

    2. The semicolon that follows the conditional is not needed. In fact, it becomes the target statement of the conditional.

    3. The conditionals can be simplified as follows...

    Code:
    var winW = xClientWidth();
    if (winW < 490) winW = "510";
    else if (winW < 520) winW = "480";  
    else if (winW < 550) winW = "450";
    else if (winW < 680) winW = "420";
    else winW = "700";
    document.write(
      "<div id='Layer1' style='position:absolute; width:200px; height:115px; "
      +"z-index:1; left:38px; top:" + winW + "'>tretet</div>"
    );
    Describe what you're trying to accomplish with this code and we'll suggest alternatives.

    The function xClientWidth() is from my dhtml library called X.

  3. #3
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi MikeFoster,

    Thanks for replying to my question, basically what i was hoping to do was create a script which sets the value of a variable to a designated number depending on the width of the browser window.

    I need the script because in netscape 4 and some versions of internet explorer my swap layer script (a basic show/hide a layer when clicking a link) gets displaced on the page (i.e a layer moves on top of other text when the browser window is smallened), therfore i need to set the value of the "top" attribute of the div layer to different numbers depending on the width of the page.

    I have tried the code you supplied but it does not work in either ie or nn. I have created a test page of the script im hoping to achieve www.redgoals.com/temp/temp/layer.html This page shows the script withought the added javascript that displays the layers(it works in both ie and nn4)

    The problem seems to arrise in nn4 when trying to write two layers using javascript instead of the ordinary html as shown on the test page.

    The page which uses the javascript to display the layers is at www.redgoals.com/temp/temp/layer-js.html

    Again i thankyou and anybody else who wants to assist for taking the time to help me with this problem.
    Last edited by redgoals; Dec 12, 2002 at 16:55.
    http://redgoals.com ... my site ... nuff said


Bookmarks

Posting Permissions

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