SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to disable an 'href' link using JS?

    Hi All

    I am making a page that uses JS to bring up a "popup <div>" when the user clicks on a particular link. I am concerned that if the users browser has JS turned off, nothing will happen when they click. I thought the way around this would be to have a valid href in the link so that if the JS doesn't work, the browser will be directed to an alternative page.

    Can I include something in my JS function so that when the user clicks the link, the JS will run and disable the href link at the same time? My thinking is, if JS is disable in the browser, this function would not work, so the browser would continue to load the href link.

    Regards, ben
    Experience is that thing which lets you know you've made the same mistake yet again.

  2. #2
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Netherlands
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onclick="yourfunction();return false;"

  3. #3
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can use the same technique as if you were doing an accessible popup, but instead of calling a new window just call the function that opens the div instead:

    Code:
    <a href="alternative_url.htm" onclick="openDiv(); return false;">pop me</a>
    On JS enabled browsers the user gets the openDiv function and the href is ignored, but on JS disabled browsers the opposite happens.

    -xDev

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that was just what I needed.
    Experience is that thing which lets you know you've made the same mistake yet again.


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
  •