How to get url without query string Parameters

How to get url without query string Parameters

In this post, i will show you how to get simple current URL with query string or without query string example using jQuery.Here is a simplw way or quick javascript code to get the simple current URL of a each page with JavascriptHow to get url without query string Parameters

location.protocol + ‘//’ + location.host + location.pathname

Here is the simple javascript code for this:-
– var param = location.href;
– var myurl_parts = url.split(‘?’);
– var main_url = myurl_parts[0];

Read Also:  how to call javascript function in html & JavaScript Define

Example 1: window.location.href

This is my first way how to get simple current URL using jQuery :

<html lang="en">
<head>
	<title>JavaScript - Simple get current URL Example</title>
	<script src="jquery-2.2.2.min.js"></script>
</head>
<body>
<script type="text/javascript">
  var simpleLiveCurl = window.location.href;
  console.log(simpleLiveCurl);
</script>
</body>
</html>

Example 2: $(location).attr(“href”)

This is pakainfo give second example how to get current URL using jQuery examples:

    <script type="text/javascript">
      var simpleLiveCurl = $(location).attr("href");
      console.log(simpleLiveCurl);
    </script>

Example

Example 3: $(location).attr(“href”)

This is simple third example you will you show to get simple current URL using jQuery :

    <script type="text/javascript">
      var simpleLiveCurl = window.location;
      console.log(simpleLiveCurl);
    </script>

Simple Get Current URL without query string using JavaScript Example

Example 1: How to get current url with or without query string example jQuery

    <script type="text/javascript">
      var simpleLiveCurl=location.protocol + '//' + location.host + location.pathname;
      console.log(simpleLiveCurl);
    </script>

Example 2: Get Query String Parameters with JavaScript

    <script type="text/javascript">
      var simpleLiveCurl=window.location.href.split('?')[0];
      alert(currentURL);
    </script>

Javascript get url without querystring Example

document.body.innerHTML = "The my simple is at this Pakainfo.com web address: " + getURL();
function getURL() {
  return location.protocol + '//' + location.host + location.pathname
}

Example