Results 1 to 3 of 3

Thread: hyperlink points to my root address when http is omitted

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,717
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default hyperlink points to my root address when http is omitted

    Code:
    <a href='www.test.com'>test</a>
    I was creating a hyperlink when I noticed that it pointed to http://www.mysite.com/test.com instead. I thought there might be something wrong with my formatting scripts, but it turns out it was because I was missing the http portion of the url.

    Before I update my formatting script to auto correct and add the http if it is missing I was wondering why this was happening.
    Last edited by james438; 07-23-2013 at 06:50 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,978
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    www.whatever.com is not a valid href, not in the sense in which it is obviously intended. It's interpreted as a file or folder name (either of which may contain . characters), and like any relative path is prepended automatically with the path to the current page.

    If you want it to go to www.whatever.com, then the proper href to use is:

    http://www.whatever.com/

    Or:

    https://www.whatever.com

    Or even:

    //www.whatever.com

    In which case the browser will take the protocol of the current page (http: or https: or even file: if it's a local page not on a server, which is why this syntax is not used more often) and prepend that to it. This can be handy though if you have a template that is used by both http and https pages on your site and you want your off site link(s) to go to the corresponding type of layer on the external site, assuming they have both.
    - John
    ________________________

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

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    james438 (07-23-2013)

  4. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,717
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Ah, thanks. I believe when I first worked on web design I noticed this behavior and found that formatting it correctly took care of that, but never really learned why.
    To choose the lesser of two evils is still to choose evil. My personal site

Similar Threads

  1. Cookie only serving pages on root directory?!
    By mrmozer in forum JavaScript
    Replies: 10
    Last Post: 04-19-2009, 02:50 AM
  2. All Levels Menu - Root URL Setting?
    By dsontag in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 01-25-2009, 12:03 AM
  3. Ultimate Fade-in slideshow - relative to root or not?
    By student101 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 12-18-2008, 04:40 PM
  4. Replies: 2
    Last Post: 09-09-2008, 03:01 PM
  5. root level link on Drop Down Tab Menu
    By dan00el in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 01-14-2007, 07:01 AM

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
  •