I want to add a text in the URL after # and then reload the page.
I have done:
<a href="current_url+'#'+sample" onclick="location.reload();">Click Here</a>
and it is working fine in Google Chrome, but in firefox it reloads the page but the url fragment '#sample' is not there. That means it gets me back on the same page without the # string. But I need it for sure.
I have also tried:
$('a').click(function(){
location.reload(true); //even window.location.reload(true);
});
But got no positive result.
What should I do?
通过在锚标记的onclick(带有window.location)中添加链接来解决此问题。
<a href="javascript:void(0)" onclick="window.location='current_url+'#'+sample'; location.reload();">Click Here</a>
Basically, you take the current url ie document.location.href
and add it the text you want:
<a href="javascript:void(0);" onclick="changeUrl(sample);">Click Here</a>
function changeUrl(text) {
document.location.href = document.location.href + "#" + text;
}
Note that this solution doesn't require jQuery.
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.