How Is Origin Determined?

Browsers will compare two URLs to determine the origin based on a number of factors. These factors include the domain name, the application layer protocol, and in many browsers, the port used.

For example, say that we are making AJAX requests from a script on to access resources on other pages. Table A-1 outlines the results for several different URLs.

Table A-1. Results of making an AJAX request from a script on

URL requested




Same host and protocol


Different port


Different protocol (https)


Different host (not an exact match)


Different host (subdomain)

Understanding these rules when you’re working with client-side scripting languages like JavaScript will save you a lot of headaches when development begins.

Get Programming Social Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.