简体   繁体   中英

replace current url without reloading the page

I want to take the current URL from browser and replace the last number param by other number, my example URL:

app#!folder/1/document?p=1

the param to replace - ?p=1 into ?p=3

the param number is generated dynamically so I have to take the param from URL

I want to execute this JavaScript as String, thanks a lot for any help

I reslove the problem(VAADIN FRAMEWROK) without using javascript

String url = Page.getCurrent().getUriFragment().toString();
url = url.replaceAll("\\?p=([0-9])?", "?p=1");
Page.getCurrent().setUriFragment(url, true);

除非我遗漏了什么,否则就像使用String#replace()一样

url = url.replace("?p=1", "?p=3");

Note that a modification to the current URL will reload the page unless it happens in the hash part (after the # character), which is obviously what you're trying to do.

The current URL can be modified in javascript via the location.href variable:

location.href = location.href.replace("p=1", "p=3");

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