| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/API/Location | [Back] [Original] |
Get to know MDN better
URL
<span id="href" title="href"
><span id="origin" title="origin"
><span id="protocol" title="protocol">https:</span>//<span
id="host"
title="host"
><span id="hostname" title="hostname">example.org</span>:<span
id="port"
title="port"
>8080</span
></span
></span
><span id="pathname" title="pathname">/foo/bar</span
><span id="search" title="search">?q=baz</span
><span id="hash" title="hash">#bang</span></span
>
html {
display: table;
width: 100%;
}
body {
display: table-cell;
text-align: center;
vertical-align: middle;
font-family: Georgia;
font-size: 175%;
line-height: 1em;
white-space: nowrap;
}
[title] {
position: relative;
display: inline-block;
box-sizing: border-box;
line-height: 2em;
cursor: pointer;
color: gray;
}
[title]::before {
content: attr(title);
font-family: monospace;
position: absolute;
top: 100%;
width: 100%;
left: 50%;
margin-left: -50%;
font-size: 60%;
line-height: 1.5;
background: black;
}
[title]:hover::before,
:target::before {
background: black;
color: yellow;
}
[title] [title]::before {
margin-top: 1.5em;
}
[title] [title] [title]::before {
margin-top: 3em;
}
[title] [title] [title] [title]::before {
margin-top: 4.5em;
}
[title]:hover,
:target {
position: relative;
z-index: 1;
outline: 50em solid rgba(255, 255, 255, 0.8);
}
document.body.addEventListener("click", (event) => {
event.preventDefault();
window.location.hash = event.target.hasAttribute("id")
? `#${event.target.getAttribute("id")}`
: "";
});
Location.ancestorOrigins DOMStringList Location
Location.hrefLocation.protocol ':' URL
Location.hostURL (':')
Location.hostnameURL
Location.portURL
Location.pathnameURL '/' URL
Location.searchURL '?' URLSearchParams URL.searchParams
Location.hashURL '#'
Location.origin Location.assign()URL
Location.reload()URL
Location.replace() URL assign() replace() History
Location.toString()URL Location.href
// location: https://developer.mozilla.org:8080/en-US/search?q=URL#search-results-close-container
const loc = document.location;
console.log(loc.href); // https://developer.mozilla.org:8080/en-US/search?q=URL#search-results-close-container
console.log(loc.protocol); // https:
console.log(loc.host); // developer.mozilla.org:8080
console.log(loc.hostname); // developer.mozilla.org
console.log(loc.port); // 8080
console.log(loc.pathname); // /en-US/search
console.log(loc.search); // ?q=URL
console.log(loc.hash); // #search-results-close-container
console.log(loc.origin); // https://developer.mozilla.org:8080
location.assign("http://another.site"); // load another page
| HTML # the-location-interface |
Location : Window.location Document.location.URL, URLSearchParamsLocationBeforeUnloadEventDOMStringMapErrorEventHTMLAnchorElementHTMLAreaElementHTMLAudioElementHTMLBRElementHTMLBaseElementHTMLBodyElementHTMLButtonElementHTMLCanvasElementHTMLDListElementHTMLDataElementHTMLDataListElementHTMLDialogElementHTMLDivElementHTMLDocumentHTMLElementHTMLEmbedElementHTMLFieldSetElementHTMLFormControlsCollectionHTMLFormElementHTMLFrameSetElementHTMLGeolocationElementHTMLHRElementHTMLHeadElementHTMLHeadingElementHTMLHtmlElementHTMLIFrameElementHTMLImageElementHTMLInputElementHTMLLIElementHTMLLabelElementHTMLLegendElementHTMLLinkElementHTMLMapElementHTMLMediaElementHTMLMenuElementHTMLMetaElementHTMLMeterElementHTMLModElementHTMLOListElementHTMLObjectElementHTMLOptGroupElementHTMLOptionElementHTMLOptionsCollectionHTMLOutputElementHTMLParagraphElementHTMLPictureElementHTMLPreElementHTMLProgressElementHTMLQuoteElementHTMLScriptElementHTMLSelectElementHTMLSourceElementHTMLSpanElementHTMLStyleElementHTMLTableCaptionElementHTMLTableCellElementHTMLTableColElementHTMLTableElementHTMLTableRowElementHTMLTableSectionElementHTMLTemplateElementHTMLTextAreaElementHTMLTimeElementHTMLTitleElementHTMLTrackElementHTMLUListElementHTMLUnknownElementHTMLVideoElementHashChangeEventHistoryImageDataMessageChannelMessageEventMessagePortNavigatorPageRevealEventPageSwapEventPageTransitionEventPluginPluginArrayPromiseRejectionEventRadioNodeListTimeRangesUserActivationValidityStateWindowWorkletGlobalScope| Web Proxy Viewer | New URL | Original Page |