How to get the current URL using AngularJS ? Last Updated : 08 Nov, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to get the current URL with the help of AngularJS, along with knowing its basic implementation through the examples. This task can be accomplished in 2 ways, i.e., by implementing the $location.absURL() method to get the complete URL of the current page, & the 2nd-way implements the split() method that is appended with the absURL() method to get the domain name of the URL. We will explore both approaches for getting the current URL using AngularJS. $location.absURL() method: The $location service facilitates to parse of the URL in the address bar & makes the URL avail to an application. The absUrl() Method returns the full path of your page and it is a read-only method. Syntax: $location.absURL();Example 1: in this example, we are using the $location.absURL() method to get the complete URL of the current page. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function ($scope, $location) { $scope.url = ''; $scope.getUrl = function () { $scope.url = $location.absUrl(); }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3>Get current URL in angularJS</h3> <div ng-app="app"> <div ng-controller="controller"> <p>Url = {{url}}</p> <input type="button" value="Click to get URL" ng-click="getUrl()"> </div> </div> </body> </html> Output: split() method: This method can also be used to get the domain name of the URL by appending it after the absURL() method. Example 2: Similar to the previous example but using the split() method to get the domain name of the URL. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function ($scope, $location) { $scope.url = ''; $scope.getUrl = function () { // Will change the current url to // ide.geeksforgeeks.org $scope.url = $location .absUrl().split('/')[2];; }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> Get current URL in angularJS </h3> <div ng-app="app"> <div ng-controller="controller"> <p>Url = {{url}}</p> <input type="button" value="Click to get URL" ng-click="getUrl()"> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to get the current URL using AngularJS ? P PranchalKatiyar Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Questions Similar Reads How To Get The URL Parameters Using AngularJS? In AngularJS, retrieving URL parameters is essential for managing dynamic content and user interactions based on the URL state. In this article, we'll learn various approaches to achieve this.Table of ContentApproach 1: Using ActivatedRoute ServiceApproach 2: Using Router ServiceApproach 3: Using UR 3 min read How to encode/decode URL using AngularJS ? In this article, we will see the mechanism to encode/decode URL using AngularJS, along with knowing the different methods available to accomplish the given task, & will understand it through the illustration. A URL specifies a resource and its access protocol.Encode URL: URL Encoding is a way to 3 min read How to Get the Current URL using JavaScript? Here are two different methods to get the current URL in JavaScript.1. Using Document.URL PropertyThe DOM URL property in HTML is used to return a string that contains the complete URL of the current document. The string also includes the HTTP protocol such as ( http://).Syntaxdocument.URLReturn Val 1 min read How to Change Image Source URL using AngularJS ? Here the task is to change the source URL of the image with the help of AngularJS.Approach: The approach is to change the URL of the image when the user click on button. When a user clicks on a button then a method is called along with the new URL, that method replaces the new URL with the old one i 2 min read How to get current_url using Selenium in Python? While doing work with selenium many URL get opened and redirected in order to keeping track of URL current_url method is used. The current_url method is used to retrieve the URL of the webpage the user is currently accessing. It gives the URL of the current webpage loaded by the driver in selenium. 2 min read Like