URL (Uniform Resource Locator)

What is a URL?

A URL (Uniform Resource Locator) is a unique identifier used to locate a resource on the Internet. It is also referred to as a web address. URLs consist of multiple parts — including a protocol and domain name — that tell a web browser how and where to retrieve a resource.

End users use URLs by typing them directly into the address bar of a browser or by clicking a hyperlink found on a webpage, bookmark list, in an email or from another application.

Syntax of a URL:

scheme://prefix.domain:port/path/filename  

Here,

  • scheme is used to define the type of Internet service (most common is http or https).
  • prefix is used to define a domain prefix (default for http is www).
  • domain is used to define the Internet domain name (like javaTpoint.com).
  • port is used to define the port number at the host (default for http is 80).
  • path is used to define a path at the server (If omitted: the root directory of the site).
  • filename is used to define the name of a document or resource.

Following is a list of some common types of schemes used in URL:

  • http(HyperText Transfer Protocol):Common web pages. Not encrypted.
  • https (Secure HyperText Transfer Protocol):Secure web pages. Encrypted.
  • ftp(File Transfer Protocol): Downloading or uploading files.
  • file: A file on your computer.

URL Encoding

URLs can only be sent over the Internet using the character set. If a URL contains characters outside the ASCII set, the URL has to be converted.

URL encoding converts non-ASCII characters into a format that can be transmitted over the Internet.

URL encoding replaces non-ASCII characters with a “%” followed by hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign, or %20.

ASCII Encoding Examples

Your browser will encode input, according to the character-set used in your page.

The default character-set in HTML5 is UTF-8.

CharacterFrom Windows-1252From UTF-8
%80%E2%82%AC
£%A3%C2%A3
©%A9%C2%A9
®%AE%C2%AE
À%C0%C3%80
Á%C1%C3%81
Â%C2%C3%82
Ã%C3%C3%83
Ä%C4%C3%84
Å%C5%C3%85

Related Posts

What are custom events in JavaScript?

Custom events are the events that allow you to decouple the code you want to run after a specific piece of code runs. There are various in-built events…

How to use nested for loop in JavaScript?

We use the for loop statement of JavaScript for repeating a set of statements inside the loop body a specified number of times. A nested for loop, as the…

What are the basic rules for JavaScript parameters?

A JavaScript function is a code that performs a particular task. The function parameters are the name list in the function definition. Parameters are also known as…

How to stop refreshing the page on submit in JavaScript?

Using event.preventDefault() to stop page refresh on form submit In this section, we will see how to use event.preventDefault() to stop page refresh on form submission. The event.preventDefault() restricts the default…

Target a Window Using JavaScript or HTML

TARGET attribute of HTML A link’s opening named frame or window is specified using the Target attribute of the <a> anchor tag. The concluding </a> tag in…

What is the role of deferred scripts in JavaScript?

Since JavaScript is a loosely typed language, you are not required to correctly predict the kind of data that will be kept in a variable. Depending on the information…