", "text": "<p>What is the purpose of the following script in head?</p>\n\n<pre class="prettyprint"><code><head>\n<script>document.write('<base href="' + document.location + '" />');</script>\n...\n</head>\n</code></pre>\n\n<p>I somewhat understood that base href is used to set the initial portion of default path. So where does this set the url to?\nLater on I'm using</p>\n\n<pre class="prettyprint"><code><body ng-app="plunker" ng-controller="NavCtrl">\n <p>Click one of the following choices.</p>\n <ul>\n <li ng-class="{active: isActive('/tab1')}"><a href="#/tab1">tab 1</a></li>\n <li ng-class="{active: isActive('/tab2')}"><a href="#/tab2">tab 2</a></li>\n </ul>\n <pre>{{ path }}</pre>\n</body>\n</code></pre>\n\n<p>with the following controller:</p>\n\n<pre class="prettyprint"><code>var app = angular.module('plunker', []);\n\napp.controller('NavCtrl', function($scope, $location) {\n $scope.isActive = function(route) {\n $scope.path = $location.path();\n return $location.path() === route;\n };\n});\n</code></pre>", "answerCount": 1, "upvoteCount": 773, "dateCreated": "2014-07-10 10:27:21", "dateModified": "2022-10-12 12:17:41", "author": { "type": "Person", "name": "archit" }, "acceptedAnswer": { "@type": "Answer", "text": "<p>The <code><base></code> element specifies the base URL to use for all relative URLs contained within the document.</p>\n\n<p>From the Mozilla Developer Network definition:</p>\n\n<blockquote>\n <p>The Document.location read-only property returns a Location object,\n which contains information about the URL of the document and provides\n methods for changing that URL and load another URL.</p>\n</blockquote>\n\n<p>In your case it sets the <code>base href</code> to the current URL. Additionally, <code>document.location</code> is equivalent to <code>document.location.href</code>.</p>", "upvoteCount": 113, "url": "https://exchangetuts.com/scriptdocumentwritebase-href-documentlocation-script-1641308824510167#answer-1658607737890957", "dateCreated": "2022-10-10 23:17:41", "dateModified": "2022-10-12 12:17:41", "author": { "type": "Person", "name": "Luke Peterson" } } } }