'); What is the purpose of the following script in my head? ...">

<script> document.write ('<base href = "' + document.location + '" / ">'); </script>

What is the purpose of the following script in my head?

<head>
<script>document.write('<base href="' + document.location + '" />');</script>
...
</head>

I understood a little that base href is used to set the initial part of the path by default. So where to set the url? Later i use

<body ng-app="plunker" ng-controller="NavCtrl">
    <p>Click one of the following choices.</p>
    <ul>
        <li ng-class="{active: isActive('/tab1')}"><a href="#/tab1">tab 1</a></li>
        <li ng-class="{active: isActive('/tab2')}"><a href="#/tab2">tab 2</a></li>
    </ul>
    <pre>{{ path }}</pre>
</body>

with the following controller:

var app = angular.module('plunker', []);

app.controller('NavCtrl', function($scope, $location) {
    $scope.isActive = function(route) {
        $scope.path = $location.path();
        return $location.path() === route;
    };
});
+4
source share
1 answer

The element <base>specifies the base URL for all relative URLs contained in the document.

From the Mozilla Developer Network definition:

Document.location Location, URL- URL- URL-.

base href URL. , document.location document.location.href.

+5

Source: https://habr.com/ru/post/1547886/


All Articles