title: getBaseURL() javascript call function in a href=""
body: <p>I am calling the based url through javascript in a html page and I want to add the base url to call a link</p>
  
  <p>eg.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;a href="getBaseURL()/filepath/index.html"&gt;Page&lt;/a&gt;
  </code></pre>
  
  <p>The javascript is as follows:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>function getBaseURL() {
      var url = location.href;  // entire url including querystring - also: window.location.href;
      var baseURL = url.substring(0, url.indexOf('/', 14));
  
      if (baseURL.indexOf('http://localhost') != -1) {
          // Base Url for localhost
          var url = location.href;  // window.location.href;
          var pathname = location.pathname;  // window.location.pathname;
          var index1 = url.indexOf(pathname);
          var index2 = url.indexOf("/", index1 + 1);
          var baseLocalUrl = url.substr(0, index2);
  
          return baseLocalUrl + "/";
      }
      else {
          // Root Url for domain name
          return baseURL + "/";
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Its just to get any base URL from the domain in question. Also, I got this code from a tutorial so any suggestions that will require less processing would be great thanks</p>
  
  <p><strong>SECOND EDIT</strong></p>
  
  <p>Hi All thanks for your answers so far, however, I am looking to call the function to the html tag  as in <code>&lt;a href="getURL()/filepath/file.html&gt;&lt;/a&gt;</code>. This is where the problem lies, I am unsure how to do that</p>