SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed: Using href:javascript and anchor links on same page

    I'm working on a project where we're using JavaScript to let users swap styles on a page. To accomplish this, I'm calling the script via href="javascript:swapcss()" on the switch styles button.

    Some pages on the site have anchor links. On those pages, if someone swaps styles without hitting any of the anchor links, all is well. But if someone hits an anchor link and then hits the swap button (at this point the URL is pageid.html#anchor), the page just reloads to their anhor point without swapping styles.

    Does anyone have a workaround handy? I've tried several alternatives I've found online (href="#" onClick="action"; href="javascript void(0)" ). Nothing works for this case yet.

    Example: http://www.livedaily.com/artist/569.html
    Hit the "change view" button to swap styles back and forth.
    Then hit the "articles" anchor link, scroll up and try to swap styles. You'll just bounce down to the anchor link (note that after doing this, if you manually reload the page, your style swap happens because the cookie apparently writes even though the page doesn't reload to show the selected style).
    Last edited by Mendo Media; Jul 8, 2003 at 12:44.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know... the same thing happens on MS IE6 on MS WinXP.

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Why links? I'd use a button instead.
    HTML Code:
    <button onclick="swapcss();">Swap CSS</button>
    NOTE: The <button> tag doesn't have to be in a form.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinnie, I think the site's using links because they've got an image button. Try this:

    Code:
    <input type="image" src="/Path/To/Image" onclick="SwapCss();" />


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
  •