SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    this.href returns url with www prefix

    I was having a seemingly intermittent problem but I was eventually able to filter it down to the following.

    I use "this.href+'#sections'" in the context of jQuery .load command. when it works, it will fetch #sections part of the target page and do Ajax load on a displayed page. Sometimes this does not work.

    Looking at the Chrome console, I saw a page http://mysite.com was requesting http://www.mysite.com/target.html. Since the browser considered this as a cross site reference, it refused to load the content. Obviously, when a page displayed is http://www.mysite.com, everything works.

    So my question is why 'this.href' returns 'www.mysite.com' instead of 'mysite.com' even when a displayed page is without "www" prefix?

    I modified the .htaccess file to redirect the www-less site request to www site and now the script always works, but this feels like a kludge.
    Is this the way 'this.href' supposed to work or am I doing something wrong? Any advice is greatly appreciated.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by adachim View Post
    So my question is why 'this.href' returns 'www.mysite.com' instead of 'mysite.com' even when a displayed page is without "www" prefix?
    You will always receive the same domain from that, it will only differ if it's being retrieved from a different location.

    If you would like clarification o this, please provide a test version of the code that you had a bad experience on, so that additional testing by us can help to narrow down the scope of things to the actual cause of the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •