Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: href="?"

  1. #1
    Join Date
    May 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default href="?"

    i have a link which i want to change the visibility of a hidden table. it all works fine except i need to put something in the href="" of the link so the css works with it. i put a # which works, but it changes the url of the page. is there something that i could put in it that doesnt change anything?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, depending on how you change the visibility of the hidden table, you could probably use "return false;" in the onclick attribute like so:

    Code:
    <a href="#" onclick="theFunction(); return false;">Link</a>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There are various ways to do this, and each is weird in some way.

    <a href="javascript:doStuff();">
    is one option, but would be weird for a browser without javacript and also looks weird to an inexperienced user on the status bar (they think they link goes to javascript:something). It might also make them think there is some weird security risk. Though it's the same as the more behind-the-scenes methods, the user would see it and perhaps be more worried.

    <a href="#" onClick="...">
    As you have, this does add the # to the url, but that's just a target. In some cases, you could make it work, like href="#pic1", if you're loading images. That might make it seem a bit more logical to the user.
    I agree, though, that this is annoying.

    Using return false is definitely the best option, as said above. (However, I prefer using "return [javascript]", which returns the JS, rather than the href, and is less to type, and I think might be more compatible.)
    One thing to consider, though, is having a pure-html (non-javascript) backup. That's what I like about 'return':

    With the example of a popup window:
    <a href="popup.htm" onClick="return window.open(this.href);">

    That would popup a window of the same value as the href of the tag, and do that instead (due to 'return') of going to the link. In a browser that doesn't have javascript, that's great, so they can still go to the link, rather than not being able to access the content. In fact, adding the target="_blank" attribute is nice, so you have a 'popup' window even with just html.


    Anyway, that might not fit exactly what you are doing, but the idea of linking to a page as a substitute for users who can't access the javascript might be a good idea.

    for example, if you had an image gallery:
    <a href="image03.jpg" onClick="return changeImg(this.href);" target="_blank">
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by djr33 View Post
    With the example of a popup window:
    <a href="popup.htm" onClick="return window.open(this.href);">
    With the above and similar, when javascript is enabled, it will execute both the new window and change the main page. The only way to be sure that it doesn't is to return false after opening the new window:

    HTML Code:
    <a href="popup.htm" onClick="window.open(this.href);return false;">
    If javascript is disabled, this will load the image in the current window. With javascript, it will leave the current window alone and attempt a pop up (subject to blocking, but allowed with most user's settings).

    With your other exmple:

    <a href="image03.jpg" onClick="return changeImg(this.href);" target="_blank">
    This will execute the href, even with javascript enabled, unless the function changeImg itself returns false.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    How very strange. Nevermind, then. I was sure that worked. Maybe it's something overlooked in some browsers, so when I tried it, I thought it was right?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    Code:
    <a href="javascript:" onMouseOver="var statusbar="Change table visibility"; window.status=statusbar" onClick="TheFunction();">link</a>
    Change the stuff in red to your own stuff.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    1. Thanks for bumping up a thread that's already been answered A COUPLE OF MONTHS AGO. You're just trying to boost your post count.

    2. The code's wrong.
    Code:
    <a href="javascript:" onMouseOver="var statusbar="Change table visibility"; window.status=statusbar" onClick="TheFunction();">link</a>
    should be
    Code:
    <a href="#" onmouseover="var statusbar='Change table visibility'; window.status='statusbar';" onclick="TheFunction();">link</a>
    3. This code only works in IE. FF does not let you to tamper with the status bar, and I think some other browsers to.
    4. Don't try and hide everything to the user, it'll just annoy them.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    1. We have absolutely no clue if he still needs help.
    2. Yes, the code was wrong.
    3. I didn't notice how old this thread was.
    4. I don't even pay attention to my post count nowadays.
    5. Yes, the code does only work in IE, but that's fine, considering that about 50&#37; of all people use it, including me.
    6. What am I hiding from the user? I'm telling them it will change the table visibility, which it will. Do they expect the link to point to changeVisibility()?
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    1. We have absolutely no clue if he still needs help.
    There were no further questions, so it's safe to assume so.
    3. I didn't notice how old this thread was.
    How did you even stumble onto it?
    5. Yes, the code does only work in IE, but that's fine, considering that about 50&#37; of all people use it, including me.
    That means it won't work for at least half your visitors. This isn't such a problem if there's non-JS fallback, as of course there should be, but you should at least have your code error out gracefully (try...catch is your friend). When it's simple to make it more compatible, however, there's really no excuse. None of this applies here, of course, where it will degrade gracefully anyway and isn't vital.
    2. The code's wrong.
    So's yours: those quotes will cause the literal string 'statusbar' to be displayed.
    Code:
    <a href="#" onmouseover="status = 'Change table visibility';return false;" onmouseout="status = ''; return true;" onclick="TheFunction(); return false;">link</a>
    But, of course, to use an <a> element purely to fire Javascript is an abuse of the element anyway. Use a button, or a generic element such as <span>.
    3. This code only works in IE. FF does not let you to tamper with the status bar, and I think some other browsers to.
    Not quite accurate. Most modern browsers disable status-bar shenanigans by default, but it's usually an option. Either way, it doesn't really matter: all browsers of which I know simply don't do anything when status bar modifications are disabled, so it degrades nicely anyway for this non-vital function.
    4. Don't try and hide everything to the user, it'll just annoy them.
    I agree with techno_race on this one. So long as the provided message is an accurate description of what the link's meant to do, it will actually be more informative than a Javascript function name or a hash in the status bar.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    How did you even stumble onto it?
    I think I was browsing the HTML forum and forgot what page I was on.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

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
  •