JavaScript HTML Help - Plz Guide its URGENT

Discussion in 'JavaScript' started by prismmb, Sep 26, 2006.

  1. #1
    Hello Big Brothers

    I have one website and Here is Template for it

    in this template i am generating menu by javascript its generating fine with 800 x 600 Screen Resolution but when it comes to 1024 x 768 then its not working

    i am calling .js file from body part in my html page so is there any condition in HTML with

    if Screen Resolution = 800 x 600 then
    call file 1
    else
    call file 2
    endif

    I want this menu at right place in any Screen Resolution.

    Plz Guide me its Urgent

    Thanks in Advance
     
    prismmb, Sep 26, 2006 IP
  2. Evoleto

    Evoleto Well-Known Member

    Messages:
    253
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hello, my proposed solution follows. It expanded it a little to make it suitable for more screen resolutions:

    
    <script type='text/javascript'>
    
    // we will use the following function in order to correctly call the extra javascript files
    
    function include_dom(script_filename) {
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', script_filename);
        html_doc.appendChild(js);
        return false;
    }
    
    var screenSize = screen.width + "x" + screen.height;
    
    switch( screenSize ) {
        case "800x600": include_dom("my_menu/800.js");
        case "1024x768": include_dom("my_menu/1024.js");
        default: include_dom("my_menu/standard.js");
    }
    </script>
    
    Code (markup):
    Hope this helps, good luck! ;)
     
    Evoleto, Sep 27, 2006 IP
  3. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi!

    Don't check the user's screen size by scripting. There is simply no need, and your layout will break if Javascript is disabled in the user agent. Layout and scripting should be kept completely separate. Furthermore, it will break if the user's browser window is not full screen; if the resolution is neither 800x600 nor 1024x768; and in many other cases.

    Simply specify size values in percentage units in your stylesheet, and the layout will work at any resolution and browser.

    Also, I would shy away from Javascript menus: they smack of non-accessible design. If you must have menus, at least use a pure CSS solution that degrades gracefully. There are many good examples available by searching the net.

    Regards
    - P
     
    penagate, Sep 27, 2006 IP