On window.location.href = Window.location.href The problem of refreshing the page
In JS can use window.location.href = window.location.href to refresh the page (there are many other ways, of course),
The problem comes back when you refresh the page using this method, as follows:
Java code
<body onload= ' alert ("AAA"); ' >
<script>function Refresh ()
{
Window.location.href = window.location.href;
}
</script>
<a href = ' # ' >###</a>
<input type = ' button ' value= ' button ' onclick= ' Refresh (); '/>
</body>
<body onload= ' alert ("AAA"); ' >
<script>function Refresh ()
{
Window.location.href = window.location.href;
}
</script>
<a href = ' # ' >###</a>
<input type = ' button ' value= ' button ' onclick= ' Refresh (); '/>
</body>
Analysis of this code you will find that when the click # # #后, click the button page will not refresh.
Must see here you already know the problem, is in the click # # #后, the URL will add a #,
So the refresh () method becomes window.location.href = "www.something.com/test.aspx#"
became an anchor point.
My solution is also simple:
Java code
Window.location.href = Window.location.href.replace (/#/g, ");
Window.location.href = Window.location.href.replace (/#/g, ");
Replace all # in the URL
In general, this substitution will not have a problem, the URL generally does not contain #, after the replacement will not cause link invalidation.
PS: Although only a small problem, but the development should be noted.