본문 바로가기

[IT/Programming]/HTML related

URL | URI parser (URL 의 href, origin, protocol, host, hostname, port, pathname, search, hash 뽑아내기)

반응형
m.logPrint() is working!

<eq> and <eqq> tags are rendered to MathJax format, being enclosed by \ ( \ ) and \ [ \ ].

docuK-1 scripts started!
If this log is not closed automatically, there must be an error somewhere in your document or scripts.

Table of Contents is filled out.

Auto numberings of sections (div.sec>h2, div.subsec>h3, div.subsubsec>h4), <eqq> tags, and <figure> tags are done.

<cite> and <refer> tags are rendered to show bubble reference.

<codeprint> tags are printed to corresponding <pre> tags, only when the tags exist in the document.


Current styles (dark/bright mode, font-family, font-size, line-height) are shown.

disqus.js with id="disqus-js" is loaded.

kakao.js with id="kakao-jssdk" is loaded.

New ShortKeys (T: Table of Contents, F: Forward Section, D: Previous Section, L: To 전체목록/[Lists]) are set.

m.delayPad=512;
m.wait=1024;
wait 1196ms.
▼ Hide
Toggle a mess
Go (FS)
TofC
DocuK Log
Backward
Forward
RRA
Lists
CmtZ
CmtX
Handle CmtZ
Log in
out focus
Mode: Bright; Font: Noto Sans KR; font-size: 18.0px (10.0); line-height: 1.6;
width: 1280, height: 720, version: 2.12.18
Canonical URI: https://kipid.tistory.com/entry/URL-URI-parser-URL-의-href-origin-protocol-host-hostname-port-pathname-search-hash-뽑아내기
dg:plink (Document Global Permanent Link): https://kipid.tistory.com/300
document.referrer: Empty
This document is rendered by docuK (See also SEE (Super Easy Edit) of docuK and pure SEE).

URL | URI parser (URL 의 href, origin, protocol, host, hostname, port, pathname, search, hash 뽑아내기)

URL | URI 에서 href, origin, protocol, host, hostname, port, pathname, search, hash 을 알아내고 싶을때가 있는데, javascript 단에서 제공하는 function 이 분명 존재할거라 생각해서 스스로 짜보다가 chatGPT 통해서 물어보고 알게 된 것 공유.

TPH.Posting History

▼ Show/Hide

T1.URL 의 기본구조

▼ Show/Hide
// The entire URL
[href]=[protocol]//[hostname]:[port][/pathname][?search][#hash]
	=[protocol]//[host][/pathname][?search][#hash]
	=[origin][/pathname][?search][#hash]

// Host
[host]=[hostname]:[port]

// Origin
[origin]=[protocol]//[hostname]:[port]
	=[protocol]//[host]
▲ Hide

T2.How to get href, origin, protocol, host, hostname, port, pathname, search, hash from URL?

▼ Show/Hide
m.analysisURL=function (url) {
	let parser=document.createElement('a');
	parser.href=url;
	let res={};
	res.href=parser.href;
	res.origin=parser.origin;
	res.protocol=parser.protocol;
	res.host=parser.host;
	res.hostname=parser.hostname;
	res.port=parser.port;
	res.pathname=parser.pathname;
	res.search=parser.search;
	res.hash=parser.hash;
	return res;
};
▲ Hide
반응형
Get page views