Learnitweb

Web document origin

1. Introduction

In this tutorial, we’ll discuss what is a web document’s origin. Understanding a document’s origin is important while discussing other topics like CORS error and Window.localStorage.

A document’s origin is defined by following three things of the URL used to access it:

  • scheme (protocol). For example, http and https.
  • hostname (domain). For example, learnitweb.com
  • port. For example, port 80

2. Examples

Following are same origin:

  • https://learnitweb.com/java/tutorial1.html
  • https://learnitweb.com/java/tutorial1.html
  • https://learnitweb.com:80/java/tutorial1.html (HTTP by default uses 80)

Following are different origin:

  • https://learnitweb.com/java/tutorial1.html
  • https://learnitweb.com/java/tutorial1.html (different protocol used)
  • https://tutorials.learnitweb.com/java/tutorial1.html (different hostname used)
  • https://tutorials.learnitweb.com:8080/java/tutorial1.html (different port used)