SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what is the reason for putting ? in the href. Eg. href="?"

    Hello,

    On page 278 of "PHP and MySQL: Novice to Ninja"

    PHP Code:
    ...
    <
    a href="?">Continue shopping</a>
    ... 
    What does the ? do in the href attribute?

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Leaving href empty would link to the same page the link is located on. So if on index.php, <a href="">test</a> will link to index.php. With "?" set as a href attribute, it'll link to index.php? - having no (useful) effect at all, except maybe reloading page

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Just wait until HTML 5, when the href is entirely optional

    Avram is correct in that it links you to the page you are currently on. However there IS a difference between "" and "?". Linking with "" will reload the current URL with the same GET variables attached. Linking with "?" will remove all GET (query-string) variables from the URL.

    So if you're on index.php?members=me, and click a link with href="", you'll go to "index.php?members=me". If you click on a link with href="?", you'll go to "index.php?"
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Just wait until HTML 5, when the href is entirely optional
    Isn't it already optional? If you're defining an anchor, rather than a link? ie <a name="news">News</a>

    I presume you're saying that you would be able to do simply <a>News</a> or <a id="news">News</a> and do something with JS instead?

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Antnee View Post
    Isn't it already optional? If you're defining an anchor, rather than a link? ie <a name="news">News</a>

    I presume you're saying that you would be able to do simply <a>News</a> or <a id="news">News</a> and do something with JS instead?
    Unless I am misreading the HTML 5 document i'm looking at, any <a> that has content without an href attribute would be treated as if it had href="".
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.
    Right near the top. Haven't read the whole thing, but using <a name="foo"> is the traditional way to link to a part of the page. I believe it may be deprecated in favour of linking directly to an id on a non-anchor element

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Correction. <a name="foo" /> is the traditional way. A content-less tag.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A) I didn't mean content-less, I just didn't enter the content or closing tag, so it would be <a name="foo">Foo</a>
    B) Yours is XHTML, which IMHO should never be used unless you need to parse the content with an XML parser anyway

  9. #9
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    avram and starlion,

    those explanations make sense in light of the examples i was looking at.

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,824
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Antnee View Post
    B) Yours is XHTML, which IMHO should never be used unless you need to parse the content with an XML parser anyway
    It is perfectly reasonable to use XHTML as long as you don't need to support IE8. That's why all that XHTML5 development work with all the new tags is currently underway.

    Once IE8 is dead HTML will become unnecessary as all browsers will then support the far superior XHTML5 variant.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wait what? IE 8 doesn't use xhtml? so what should I use? just regular html in the meantime? how prevalent is ie 8?

  12. #12
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry @NewWebDesigner2, didn't see your reply until months later.

    XHTML is considered malformed HTML by most browsers unless you also use the correct MIME type, ie application/xhtml+xml. But if you used that in early IE versions you would see an XML DOM, and not a rendered web page. So if you were sending XHTML code, the browser was treating it as HTML anyway. There's no harm in using XHTML, and it's important to use it if you need to process it using an XML parser of some kind (don't forget that XML is strict, compared to HTML), but it wouldn't validate correctly.

    See here for more information: http://www.w3.org/TR/xhtml-media-types/#media-types

    You'll see that there are acceptable usages of XHTML and text/html (the default for most webservers) but I suspect that they won't cover most of your use cases.

    Lots of people think they've been using XHTML for years, but they haven't been doing it properly, frankly.


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
  •