Does the base tag affect scripts and styles in an html document?

3

Having http://exemplo.com/diretorio1/documento1.html the code:

<!DOCTYPE html>
<html>
    <head>
        <title>Uma página</title>
        <base href="http://exemplo.com/diretorio2/" />
        <script>
            function foo(){
                window.location.href= "documento2.html";
            }
            // Mais Scripts...
        </script>
        <style>
            @import url("estilo2.css");
            /* Estilos etc... */
        </style>
    </head>
    <body>
    </body>
</html>

The foo function <script> can follow up http://exemplo.com/diretorio2/documento2.html ?

Is the style in <style> able to import the file http://exemplo.com/diretorio2/estilo2.css ?

    
asked by anonymous 03.11.2014 / 14:13

1 answer

3

Yes, exact, all the relative URLs of the document.

A MDN description :

  

[...] specifies the base URL to use for all relative URLs contained within a document [...]

     

Translated: specifies the basis of the URL to use for all relative URLs in the document.

Example: link
(where I use the base for the url of an image and for the CSS) :

<base href="http://cdn.sstatic.net/stackoverflow/">
<link rel="stylesheet" type="text/css" href="all.css?v=4da5848172aa">
<div class="topbar">
    [...]
</div>
<img src="img/sprites.png?v=3c6263c3453b" alt="" />

Result:

    
03.11.2014 / 14:22