Menu

gitpiper

isSameOrigin javascript Code Snippet in 2024

objectbeginner

Last Updated: 17 July 2024

Checks if two URLs are on the same origin.

  • Use URL.protocol and URL.host to check if both URLs have the same protocol and host.
const isSameOrigin = (origin, destination) => origin.protocol === destination.protocol && origin.host === destination.host;
const origin = new URL('https://www.30secondsofcode.org/about'); const destination = new URL('https://www.30secondsofcode.org/contact'); isSameOrigin(origin, destination); // true const other = new URL('https://developer.mozilla.org); isSameOrigin(origin, other); // false

javascript snippet similar to isSameOrigin For You in July 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️