Delete part of query string from url without page reload
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Admin
- Site Admin
- Posts: 805
Delete part of query string from url without page reload
The
delPartUrl() function from the following JavaScript code can be used to
delete part of query string from page url in browser, without affecting or reloading the page.
Code: Select all
<script>
//delete part of query string from url without affecting the page
//from: https://coursesweb.net/
//receives a string with name of the part in query
function delPartUrl(p){
var pg_url = window.location.toString();
var rgx = new RegExp('[&]{0,1}'+p+'=[^&]+', 'i');
let is_p = pg_url.match(rgx);
//if p in url
if(is_p){
pg_url = pg_url.replace(is_p[0], '');
history.replaceState(null, '', pg_url);
}
}
//test, delete 'sid=...' from page address in browser
delPartUrl('sid');
</script>
- In the example above, if the initial address of the page is:
//localhost/index.php?ir=12&sid=78sdy&nm=2h
in browser it will show:
//localhost/index.php?ir=12&nm=2 (without 'sid=...').
Similar Topics
-
Link to part of another page (not working)
PHP - MySQL
First post
I`m searching for few hours now but can`t find a solution to link to a part off a page ??? I try to use this...
In one comment-page I have this...
Last post
It is strange I tried alot things nothing working correctly.
Meight my Question is wrong, Because I try from a page a link to another page but the...
-
Delete Data without Refreshing Page
JavaScript - jQuery - Ajax
First post
Happy New Year Chief.... My first two weeks I spended on bed due to illness
I wanna use a script but it does not delete the item from my sql...
Last post
O God that I did not see this `stupido me`....
Thank you very much for all the support `its working now`
-
Remove query parameter from URL in PHP
PHP - MySQL
First post
How can I remove a parameter from URL query, and display the query string without the removed parameter?
For example, i have this URL:...
Last post
You can use the queryToArray() function from the following example to make an array from URL query parameters.
With unset() remove the parameter you...
-
SSEP SQL query and ssep_pgd_1 table not exist
Scripts from this website
First post
Hi,
I am new to the SSEP. I installed the script but I got some problems with the index.
First there was an error like this:
URL: Registered -...
Last post
Did you get any error message?
When you indexed the site for first time did it worked with all pages?
Maybe it exceeds the memory limit, I don't...
-
Adding string from database into PDF
PHP - MySQL
First post
Hello Coursesweb I have a problem with my php document to convert it to PFD
I cant find out how to get results from $users into the HTML to the PDF...
Last post
Thanks MarPlo I prefer not to ask anything on stackoverflow.com
because I once typed a small i instead of I.
and received many comments about it....