Web API URL.origin PropertyReadDiscussCoursesPracticeImprove Article ImproveSave Article SaveLike Article LikeThe Web API URL.origin property returns a USVString containing the origin of the URL.Syntax:var str = URL.origin Return Value: This property returns a USVString containing the origin of the URL.Example 1:HTML<!DOCTYPE html><html> <body> <h1>GeeksforGeeks</h1> <div id="abc"></div> <button onclick="get()"> Click on Me! </button> <script type="text/javascript"> function get() { var url = new URL('https://www.geeksforgeeks.org/href#ExampleHash'); a = document.getElementById("abc"); a.innerHTML = "origin of current URL is : " + url.origin; } </script></body> </html>Output:Example 2:HTML<!DOCTYPE html><html> <body> <h1>GeeksforGeeks</h1> <button onclick="get()"> Click on Me! </button> <script type="text/javascript"> function get() { var url = new URL('https://www.geeksforgeeks.org/href#ExampleHash'); console.log("origin of current URL is :", url.origin); } </script></body> </html>Output:Supported Browsers:SafariOperaChromeEdgeFirefoxLast Updated : 27 Nov, 2020Like Article Save Article Please Login to comment...