SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I display a JavaScript link if the browser has JavaScript enabled, and yet have non-JavaScript browsers display a basic link to the next page?

    Whether the browser has JavaScript enabled or not (or doesn't support it), I want each version of the page to display only their version of the link. That is, display the JavaScript link to JS browsers, and the non-JS link to Non-JS browsers.

    One method I know is to set an ID on the non-JS link and use the style.display method to not display it for JS enabled browsers. However, this only works in IE4 and not NS4; and it does not remove the JS link for non-JS browsers.

    Anyone have any suggestions? Thanks!


  2. #2
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure what you mean by a "JavaScript Link". Are you calling a JavaScript function from a link?
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  3. #3
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, a JavaScript function from a link.

    The function is just some cookie code that opens up a Subscribe popup, and than refers the user to the link.

    The non-JavaScript link just refers them to the link.

  4. #4
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey pale,

    would this be kind of what you want:

    <script>
    document.write('<a href="javascript:dothis()">JavaScript function link</a>');
    </script>
    <noscript>
    <a href="non_javascriptLink.html">JavaScript function link</a>
    </noscript>

    Hope that helps,
    aDog

  5. #5
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's exactly what I'm looking for. B

    /me remembers seeing that somewhere at sometime in the future

    geesh, if only i coulda remembered

    Thanks, Arielladog =)


  6. #6
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also use event handlers -

    onsubmit="doThis()"
    onMouseOver="doThis()"
    onMouseOff="doThis()"
    onClick="doThis()"
    onChange="doThis()"
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's my favorite method:

    <a href="nextpage.html" onClick="myFunction('nextpage.html');return false;">...</a>

    The "return false;" in the event handler causes browsers with JavaScript enabled to ignore the href attribute. Meanwhile, JavaScript-incapable browsers will ignore the onClick and treat the tag as a normal link.

    Neat and tidy.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •