Simple JavaScript Get current url Example

Today, We want to share with you Simple JavaScript Retrieve current url Example.In this post we will show you How to get Full Request URL or Route in javascript, hear for javascript Retrieve Current URL with Parameters we will give you demo and example for implement.In this post, we will learn about How to get current url with or without query string example jQuery with an example.

Simple JavaScript Get current url Example

There are the Following The simple About How to Retrieve Full URL with parameters in JavaScript? Full Information With Example and source code.

As I will cover this Post with live Working example to develop jquery Retrieve Full url with parameters, so the how to send query string in jquery is used for this example is following below.

JavaScript Retrieve current url

More About Full Url In JavaScript

<script type="text/javascript">
	var currentURL = window.location.href;
</script>

JavaScript Retrieve current url parameters

<script type="text/javascript">
	function retriveCurrentURL(arg) {
	  var sqay = window.location.search.substring(1);
	  var datas = sqay.split("&");
	  for (var i=0;i<datas.length;i++) {
	    var uri = datas[i].split("=");
	    if (uri[0] == arg) {
	      return uri[1];
	    }
	  } 
	  alert("currentURL Parameter not found.");
	}
	// suppose url is www.your_domain_name.com?&q1=movile&q2=deepakbhaodiya;
	var currentURL = retriveCurrentURL(q1);
	alert(currentURL);// will give you movile
</script>

Javascript Full url protocal name

<script type="text/javascript">
function retriveCurrentURL(){
var currentURL_protocol = location.protocal;
alert(currentURL_protocol);// example http:: or https
}
</script>

Javascript Current url hostname

<script type="text/javascript">
function retriveCurrentURL(){
	var currentURL_host = location.hostname;
	alert(currentURL_host);// such as  -  your_domain_name.com
}
</script>

JavaScript Retrieve current url without parameters

<script type="text/javascript">
function getCurrentUrl(){
	var currentURL_protocol_host = location.protocol + '//' + location.host;
	alert(currentURL_protocol_host);// example - www.your_domain_name.com 
}
</script>

JavaScript Retrieve query strings from url

<script type="text/javascript">
function retriveCurrentURL(){
var currentURL = location.pathname;
	alert(currentURL);// 
}
</script>

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about javascript Retrieve url parameter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to get url without query string Parameters
  2.   Laravel 6.2 jQuery AJAX CRUD Tutorial
  3.   Session Flash Messages in Laravel 6 Tutorial
  4.   Top 10 Angular2 Interview Questions and Answers
  5.   Simple CSS Star Rating plugin
  6.   WordPress HTTP REST API Error Handling
  7.   ng-blur Event using Angular Example
  8.   Eloquent ORM Soft Delete in Laravel 6
  9.   Create Custom 404 Error page in laravel Example
  10.   Refresh a HTML div without page load AJAX