Jquery removes everything after a question mark in a url

I was wondering if I can delete everything after the question mark in the URL?

http://www.site.com?some_parameters_continue_forever

Can I use it .remove()? What needs to be placed inside the parameters?

thank

+5
source share
4 answers

Since the URL is controlled by the browser when the URL changes, the page reloads. Still for what you want to do, on pages where you don't need materials after type ?.

window.location = "http://www.mysite.com" //or whatever your site url is

To do this dynamically, you can use the following function and then use window.location

function getPathFromUrl(url) {
  return url.split("?")[0];
}

Note . When you change the URL of the page will be updated.

+9
source

Try this snippet:

var url = "http://www.somexample.com?a=b&c=2&d=3";
url = url.substring(0 , url.indexOf('?')+1);
+4
source

You can use this simple regex:

yourUrl.replace(/\?.+/, '')

reomve() Designed for DOM materials.

+3
source

Posting this, that worked for me in Python 3, as some of the other solutions didn't.

import re

mystring = 'http://www.example.com?some_parameters_continue_forever'
mystring_clean = re.sub(r'\?.*', '', mystring)

print(mystring_clean)
0
source

All Articles