Domanda

After the following tag:

<base href="http://mycompany.com/">

How can I e.g. include local stylesheets (local: in the same directory as the HTML file):

<script src="[what to write here?]standard.js" type="text/javascript"></script>

?

È stato utile?

Soluzione

FIRST the src/href attributes are resolved at run time by it self. You only need to specify the relative address..
SECOND If you want to use <base> tag.. All you need to do is to specify <base href="" target="">
Now all the src/href attribute you specify will be referred as relative address based on <base> tag.
Further all the links, doesn't matter you specify target or not they get it from <base> tag
For example

Altri suggerimenti

Interesting idea, although you cannot do this in HTML. I first thought of a PHP workaround, but how about this Javascript idea: (clears the base tag when required)

function BaseWorkaround(elementId) {
    var baseTag = document.getElementsByTagName("base")[0];
    var existingBaseHref = baseTag.href;
    baseTag.href = "";
    location.href = elementId;
    baseTag.href = existingBaseHref;
  }

Then on your href you could do something like

 ="BaseWorkaround('your_url_goes_here')">

First thing is that, you are including javascript, not stylesheet. Secondly, you don't need to write anything, just name of file (.css/.js) will do the job. i.e

<script src="standard.js" type="text/javascript"></script>

it's <script src="standard.js" type="text/javascript"></script> if it's in the same map. So nothing before there

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top