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

Asked

Viewed 152 times

3

Having in 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 function foo of <script>can follow up http://exemplo.com/diretorio2/documento2.html?

The style in <style> can import the file http://exemplo.com/diretorio2/estilo2.css?

1 answer

3


Yes, exactly, all relative Urls of the document.

To description of the MDN:

[...] specifies the base URL to use for all relative Urls contained Within a Document [...]

Translated: specifies the URL base to use in all relative Urls of the document.

Example: http://jsfiddle.net/4q2fpyft/
(where I use the basis for an image url and 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="" />

Upshot:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.