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 How to get form input value using AngularJS ? Given a form element and the task is to get the form values input by the user with the help of AngularJS.Approach: We are storing the data in the JSON object after the user enters it in the input element with the help of the Angular.copy(object) method. After that, data from the JSON object can be a 2 min read Get the current URL using jQuery The current URL in jQuery can be obtained by using the 'href' property of the Location object which contains information about the current URL. The href property returns a string with the full URL of the current page. We can access the value of the href property using two different methods of jQuery 2 min read How to display the Greeting Message using current time in AngularJS ? In this article, we will see how to display the Greeting Message based on the current time using Angular JS, along with understanding their basic implementation through the illustration. To display the current time in different formats, Angular JS uses the same JavaScript Date() function. Generally, 4 min read How to Open URL in New Tab using Angular ? In this article, we will learn How to open a link in a new tab using Angular. A Link is a connection from one web page to another web page. Generally, the anchor tag can be used to open URLs in a new tab in an elementary and straightforward manner. However, the window.open() method can also be utili 2 min read How to get the Base URL with PHP ? The term "Base URL" refers to the base or starting point for a set of related URLs. For example, if you have a website with multiple pages or an API with various endpoints, the Base URL is the common part shared by all those URLs. It typically includes the protocol (such as "http" or "https"), the d 2 min read Like