简体   繁体   中英

onClick on button that should reload the page without querystring not working: he reloads the same URL

I have a button with onClick attribute that should reload the page without the querystring, but it just reloads the page with the exact same URL.

This is the situation:

page url:

http://.../index.php/all-reservations?id_user=0&plate=0&from=2017-09-19&to=

the button:

<button id="resResetBtn" onclick="location.href='/index.php/all-reservations?view=allreservations'"><?= JTEXT::_('RESET_SEARCH') ?></button>

What I get is the button reloads the page with the exact same querystring. This is what I tried:

  • added the http schema to the url
  • added a "nocache" param to the new url

Any advice?

Thanks

You can remove the query string first and then reload the page. Use this line of code

window.location = window.location.href.split("?")[0];

Or, alternatively:

window.location = window.location.pathname;

or even,

window.location.replace(location.pathname);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM