How to get the URL without any parameters in JavaScript

0 votes

If I use:

alert(window.location.href);

I get everything including query strings. Is there a way to just get the main url part, for example:

http://edureka.co/somedir/somefile/

instead of

http://edureka.co/somedir/somefile/?foo=bar&loo=goo
Oct 9, 2020 in Java-Script by kartik
• 37,520 points
7,493 views

1 answer to this question.

0 votes

Hello @kartik,

This is possible, but you'll have to build it manually from the location object:

location.protocol + '//' + location.host + location.pathname

Hope it helps!!
Thank you!!

answered Oct 9, 2020 by Niroj
• 82,840 points

Related Questions In Java-Script

0 votes
1 answer

How to get the url parameters using AngularJS?

Hello @kartik, To use params simply append them ...READ MORE

answered Oct 8, 2020 in Java-Script by Niroj
• 82,840 points
10,895 views
0 votes
1 answer

How to get the host url using javascript from the current page?

Hello @kartik, Use: var host = window.location.hostname; or possibly var host ...READ MORE

answered Oct 9, 2020 in Java-Script by Niroj
• 82,840 points
1,297 views
0 votes
1 answer

How to change url after success in ajax without page reload?

Hello @kartik, Use the browser history to change ...READ MORE

answered Apr 29, 2020 in Java-Script by Niroj
• 82,840 points
9,888 views
0 votes
1 answer

How to detect if URL has changed after hash in JavaScript?

Hello @kartik, Use this code window.onhashchange = function() { ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,840 points
4,996 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
4,235 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,840 points
3,280 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
1,151 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
1,055 views
0 votes
1 answer

How to get the browser to navigate to URL in JavaScript?

Hii, This works in all browsers: window.location.href = '...'; If ...READ MORE

answered May 28, 2020 in Java-Script by Niroj
• 82,840 points
2,692 views
0 votes
1 answer

How to get the current URL with JavaScript?

Hello @kartik, Use: window.location.href As noted in the comments, ...READ MORE

answered Aug 28, 2020 in Java-Script by Niroj
• 82,840 points
1,313 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP