Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:59:54+00:00 2026-05-29T09:59:54+00:00

I know according to the spec, the href of base should be a absolute

  • 0

I know according to the spec, the href of base should be a absolute URI.

href = uri [CT]
This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.

But firefox and chrome support relative URIs, e.g. ../../, which is very important of my current project. I don’t find a better solution other than “relative base href” for my project.

Is there any hacks or workgrounds for IE to let it support relative URIs? My web pages works well in firefox and chrome now, but it has to support IE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:59:54+00:00Added an answer on May 29, 2026 at 9:59 am

    Use this function to convert your URL to the absolute:

    function toAbsURL(s) { 
         var l = location, h, p, f, i; 
         if (/^\w+:/.test(s)) { 
           return s; 
         } 
         h = l.protocol + '//' + l.host + (l.port!=''?(':' + l.port):''); 
         if (s.indexOf('/') == 0) { 
           return h + s; 
         } 
         p = l.pathname.replace(/\/[^\/]*$/, ''); 
         f = s.match(/\.\.\//g); 
         if (f) { 
           s = s.substring(f.length * 3); 
           for (i = f.length; i--;) { 
             p = p.substring(0, p.lastIndexOf('/')); 
           } 
         } 
         return h + p + '/' + s; 
       }
    

    You could use

    var base = document.getElementsByTagName('base')[0];
    base.href = toAbsURL(base.href);
    

    Example http://jsfiddle.net/tEpkx/1/

    Except that you have to detect the browser, too, and run it only for IE. Other browsers will get window.location updated by the href of the base tag automatically and this code snippet will change it again. So write it as

    <!--[if IE]>
    <script type="text/javascript">
    var base = document.getElementsByTagName('base')[0];
    base.href = toAbsURL(base.href);
    </script>
    <![endif]-->
    

    ps: <base /> is a single tag, it does not require the closing one.

    Updated to include the port number if it is set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know, according to this article that I should Sign the message, then Encrypt
i know that you could organize your files according to this structure in svn:
According to the answer on this post it states: Did you know that ReadUncommitted
We all know that you can overload a function according to the parameters: int
according to this code i dont understand about NSClassFromString how did i know viewControllerName
According to this http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html article, I defnitely should. Quote Gentle, yet insistent executive summary:
According to this: http://code.google.com/appengine/docs/whatisgoogleappengine.html it seems that GAE only uses Datastore to store data,
According to this question I know how to put an application in the autostart
According to the manual of mysql_query() and to everything I know about this function
According the Lift wiki, I know the View First concept of Lift. That's very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.