Closed
Description
<body>
<script>
const frame = document.body.appendChild(document.createElement("iframe"));
const win = frame.contentWindow;
const loc = win.location;
frame.remove();
try {
alert("String(loc): " + String(loc));
} catch (err) {
alert("String(loc) err: " + err);
}
try {
alert("loc.href: " + loc.href);
} catch (err) {
alert("loc.href err: " + err);
}
try {
alert("Type(win.location): " + Type(win.location));
} catch (err) {
alert("Type(win.location) err: " + err);
}
try {
alert("win.location.href: " + win.location.href);
} catch (err) {
alert("win.location.href err: " + err);
}
function Type(x) {
if (x === null) return "null";
return typeof x;
}
</script>
In table form:
Browser | String(loc) |
loc.href |
Type(win.location) |
win.location.href |
---|---|---|---|---|
Chrome | TypeError |
undefined |
"object" |
undefined |
Edge | "about:blank" |
"about:blank" |
TypeError |
TypeError |
Firefox | "" |
"" |
"object" |
"" |
Safari | TypeError |
undefined |
"null" |
TypeError |
Spec(?) | ?? | ?? | "object" |
?? |
This issue amazes even me in its number of ways browsers find to disagree with each other. I am also not entirely sure what the spec currently says, and what I put in that row is my best understanding. The ?? refers to the fact that the definition of Location
object's relevant Document
seems to be broken for a Location
associated with a Document
object that no longer has a browsing context.