Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!-- Please update base-javascript.html together with this -->
<!DOCTYPE html>
<meta charset="utf-8">
<title>&lt;base> and data: URLs</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<base href="data:/,test">
<base href="https://example.com/">
<div id=log></div>
<script>
test(() => {
const link = document.createElement("a");
link.href = "blah";
assert_equals(link.href, new URL("blah", document.URL).href);
}, "First <base> has a data: URL so fallback is used");
test(() => {
document.querySelector("base").remove();
const link = document.createElement("a");
link.href = "blah";
assert_equals(link.href, new URL("blah", "https://example.com/").href);
}, "First <base> is removed so second is used");
test(() => {
const base = document.createElement("base");
base.href = "data:/,more-test";
document.head.prepend(base);
const link = document.createElement("a");
link.href = "blah";
assert_equals(link.href, new URL("blah", document.URL).href);
}, "Dynamically inserted first <base> has a data: URL so fallback is used");
</script>