Need a script...

Discussion in 'Web Design and Development' started by MegaMan1311, Jul 13, 2007.

  1. MegaMan1311 macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #1
    I need a script to use if this is possible... I'm pretty sure it is, but I don't know because I am not a very advanced at coding.

    I need to display some content if Javascript is enabled, but if it is not, show different content. I can run php on the site if its needed.

    I am making an ajax navigation bar, but need to make an option for those who don't have javascript. I thought of using the noscript tag, but if they didn't have javascript, they would see both the ajax and the simple version because the ajax one involves images.

    I hope you understand what I mean. Thanks in advance.

    MegaMan1311
     
  2. tominated macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #2
    The noscript method should work seeing as AJAX is just javascript with a little xml sprinkled on top.
     
  3. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #3
    Yes, but my navigation is made of images with ajax menus coming from it. I want the images to be linked if there if javascript isn't enabled. If it is enabled, I don't want it to be linked, to make it simpler to the user.
     
  4. tominated macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #4
    oh. in that case can you post the code so we know exacly what we are dealing with?
     
  5. ppc_michael Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #5
    Ajax-powered menus? By the sound of it, that seems pretty inefficient. Why not load all of the navigation with the page?
     
  6. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #6
    You can set up a link like this:
    <a href="someplace.html" onclick="javascript: someFunction(); return false;"><img ... /></a>

    When this runs in a browser without javascript onclick is ignored. When the user clicks the link, they navigate to someplace.html.

    Notice that onclick returns false. That tells the browser to NOT follow the link. It does, however, call someFunction(). If you don't want clicking the link to do anything under javascript, just make it onclick="javascript: return false;"

    Does this help what you are doing? If not, post some code. Worse comes to worse, setup the page with the links the way you want them when javascript isn't available. Then use javascript when the page loads to modify the DOM to remove/change the links.
     
  7. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #7
    I have a horizontal navigation bar, so I need menus that drop down from each one.. I did it like this to save space. The ajax is just to make it nicer looking. If I didn't use ajax, I would have to use javascript. Why use javascript when you can use ajax?

    Unfortunately, I am still working with the site, so the ajax isn't implemented yet. I can show you what I am doing, but it won't have the menus working.

    Yes. It works great! One question, I doubt it is possible, but is there a way make it so that there isn't even a link there if javascript is enabled?

    Thanks.
     
  8. ppc_michael Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #8
    Ajax is Javascript. It's only meant for sending conditional data to/from the server. If you're doing things just to "save space" then all you really need is to show/hide DIVs.

    You could place the link in a DIV that is set to display:hidden (CSS) by default, and then use Javascript to reveal it. So if Javascript isn't running, it is never revealed.
     
  9. MegaMan1311 thread starter macrumors regular

    Joined:
    Jun 30, 2007
    Location:
    USA
    #9
    I wanted ajax for a bit of a dynamic effect.

    Would it be possible to hide a div with javascript? If so, how would I go about doing it?
     
  10. CoreWeb macrumors 6502

    Joined:
    Mar 2, 2007
    Location:
    Edge of reason
    #10
    Ajax does absolutely NO dynamic effects.

    It sounds to me like you don't know what Ajax is. Ajax is Asynchronous Javascript and XML. It is meant to allow you to download content from the server. It is all done THROUGH Javascript.

    Hiding a div in Javascript is as simple as
    Code:
    document.getElementById("divid").style.visibility = "hidden";
    That's javascript. There is no such thing as hiding a div in Ajax. Javascript is a language, Ajax is a certain convention used in some Javascript scripts. You may benefit from reading some Javascript tutorials online. There are some good ones (if you want I can try to find some for you), and you will learn the limitations/capabilities of Javascript.

    Ajax should definitely not be used for menus, though. Ajax downloads new content from the server; if you were using that in your menus you'd have to make the client's computer connect to the server any time they wanted to view the menu! That is quite inefficient. Instead, the div should be hidden by default (the "style" attribute for it should specify "visibility:hidden") and then you make it appear with Javascript.

    Also, as a side note, it may also advisable to store your menus not in divs but in more meaningful "lists" which are then styled through CSS:
    Code:
    <ul>
        <li>menu 1
            <ul>
                <li>sub item 1</li>
                <li>sub item 2</li>
             </ul>
         </li>
         <li>menu 2
             <ul>
                 <li>sub item 1</li>
             </ul>
         </li>
    </ul>
    
    Then you'd use CSS to make them all appear on one line, and strip the bullets, etc. The benefit is that it is more meaningful, and if anyone ever strips both the stylesheet and the Javascript away, it would still be readable as a list.
     

Share This Page