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];

Example 1: window.location.href

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



	JavaScript - Simple get current URL Example
	





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

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

    

Example

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

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

    

Simple Get Current URL without query string using JavaScript Example

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

    

Example 2: Get Query String Parameters with JavaScript

    

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
}

Get the URL without any parameters in JavaScript

To get the URL without any parameters in JavaScript, you can use the window.location object to get the current URL and then remove any parameters from it. Here’s an example code:

let urlWithoutParams = window.location.href.split('?')[0];

In this code, the window.location.href property returns the current URL of the page, including any parameters.

The split(‘?’)[0] method splits the URL string at the question mark (‘?’) and returns an array with two elements – the first element is the URL without the parameters, and the second element is the parameters themselves. We then simply take the first element of the resulting array to get the URL without parameters.

You can then use the urlWithoutParams variable to work with the URL without any parameters in your JavaScript code.
Example

Leave a Comment