Closed Bug 286809 Opened 15 years ago Closed 9 years ago

Scripts loaded after BASE href change ignore it


(Core :: DOM: Core & HTML, defect)

Windows XP
Not set





(Reporter: danswer, Unassigned)




(3 files, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1

If the first thing I do in a page is to change the href of the <BASE href=...>
element, then subsequent <SCRIPT> tags will not see this change and load based
off the original BASE element.

Reproducible: Always

Steps to Reproduce:
The first two attachments I'm planning to provide will be simple javascripts
that merely put up an alert to show that they were loaded.  Bring up the third
file.  If only one of the two javascript files get loaded then the problem exists.
Actual Results:  
With Firefox 1.0.1, there is only one alert.  The BASE change has been ignored.
 With IE both javascript files load.

Expected Results:  
I expect that scripts loading will respect the current BASE href's setting and
not  load based off the original one.

This actually has real world implications:

If I'm developing on a local machine, then my pages can be accessed via (1)
double clicking, (2) via localhost (or an entry in the hosts file) or similarly
locally, (3) externally from the web.

If I have a .js file that I wish to have run through my Apache server (because
it's really a .php file that spits out javascript), then simply putting the file
name will fail on (1) because (1) looks for a file.  But putting the (possibly
only anticipated) domain name is not good either because the machine may not be
hooked to the web or the domain may be inaccessible.

So, my idea was to put the planned domain name in the <BASE href=...> element
but if I detect that the protocol is file: or that the request is not from the
internet, then swap the href to localhost to ensure processing.  Works as
desired on IE and this way I can move pages to the web without having to
remember to make changes.  Unfortunately, it precludes efficient testing with

This is related to Bug 209275, but there the issue is that changes don't affect
extant elements.  I've situated the alerts to show that the scripts have not yet
been loaded by the time the BASE's href attribute has changed.

Csaba Gabor from Vienna
The first of two .js files - this one has an absolute reference to it so is
sure to get loaded.  The content:

alert("The first of the two scripts as been loaded");
The second of two .js files - this one will get loaded if the <BASE href=...>
change is respected.  The content is:

alert("The second of the two scripts has been loaded.\n"+
      "This one only makes it if the href change of the BASE element is
Attached file The main test page. (obsolete) —
This is the main test page.  It should show the following alerts:
1)  Load interrupted with Base's href = ...
    This shows that the BASE's href has been changed before the two .js scripts
have been loaded.  There will be some delay after this as the two javascript
files are looked for.

2)  The first of two scripts has been loaded.
    This shows that the hardcoded load works, and that this successful load
happens only after the BASE has been changed and the first alert has passed.

3)  The second of the two scripts has been loaded.
    This one only makes it if the href change of the BASE element is recognized

    If this alert shows, then the BASE element's href change is recognized and
there is no bug.  At submission time, Firefox 1.0.1 was not showing this alert.
 IE 6 does.

4)  Doc loaded.  Done.

    The final alert, just to know that there wasn't a terminal error.

Here is the code:
<html><head><base href="">
<script type='text/javascript'>
// next line changes the BASE href in FF and IE, but only IE takes note
document.getElementsByTagName('BASE')[0].href = location.pathname;
function baseRef() { return document.getElementsByTagName('BASE')[0].href; }
alert("Load interrupted with Base's href = " + baseRef());
<title>Base rewriting demo</title>
<body onload="alert('Doc loaded. Done.')">
<script type='text/javascript'
<script type='text/javascript' src='attachment.cgi?id=177937'></script>
Attached file The main test page
Oops, let me try this again.  One line changed in the above code.  It is now:
document.getElementsByTagName('BASE')[0].href = location.href;
Attachment #177939 - Attachment is obsolete: true
Depends on: 209275

User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2)
Gecko/20050331 Firefox/1.0+
This is an automated message, with ID "auto-resolve01".

This bug has had no comments for a long time. Statistically, we have found that
bug reports that have not been confirmed by a second user after three months are
highly unlikely to be the source of a fix to the code.

While your input is very important to us, our resources are limited and so we
are asking for your help in focussing our efforts. If you can still reproduce
this problem in the latest version of the product (see below for how to obtain a
copy) or, for feature requests, if it's not present in the latest version and
you still believe we should implement it, please visit the URL of this bug
(given at the top of this mail) and add a comment to that effect, giving more
reproduction information if you have it.

If it is not a problem any longer, you need take no action. If this bug is not
changed in any way in the next two weeks, it will be automatically resolved.
Thank you for your help in this matter.

The latest beta releases can be obtained from:
This bug was confirmed in comment 5, but comment 6 obliges me to respond, so I
am confirming (see comment 3 for how to run the test) that it still exists in
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20051007
Firefox/1.6a1 [Deer Park Alpha 2, downloaded today]

In addition, since I'm here, may as well do some overdue cleanup.  Bug 209275
depends on this one and not the other way round: If this one, gets fixed, that
does not imply 209275 gets "fixed", but if 209275 is "fixed" that implies this
one is fixed.  Hence that one depends on this one.

I'd also like to reiterate that there is a real use case for developers that
I've described in the 2nd half of the original report.

Csaba Gabor from Vienna 
Blocks: 209275
No longer depends on: 209275
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
No longer blocks: 209275
Depends on: 209275
Please retest now that bug 209275 is fixed?
Today I retested with Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:

It still does not work as expected with FF (ie. 3rd alert is missing)
I also tested with IE 8, where it does work as expected (ie. 4 total alerts)
> Today I retested with Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
> rv:

Uh...  Is that really what you tested with?  That's a build of Firefox _3_.  It's not only out of support (and has been for months), but is based on Gecko from back in 2008.  So of course it doesn't have this fix, which was checked in in late 2009.

To properly test this, you need to test a trunk nightly.
Or the Firefox 4 beta.
WFM. Please reopen if you still see the issue in Firefox 4.
Closed: 9 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.