Question

I have this simple HTML button on my page:

<button type="button" onclick="window.location='http://localhost/test.php?param1=A&param2=B#MyANCHOR';"></button>

The problem: it executes the anchor command, positioning #MyANCHOR on top, but it doesn´t reload the page. It should execute the URL, reloading it and after it, then positioning the #MyANCHOR on top after it loads.

I spent some time looking for some solution here, but I wouldn't like to use jQuery on it, because I think I can reach my objective with a simple modification, mabe changing the onClick content, some simple detail, what else... suggestions?

Thanks.

Was it helpful?

Solution

I'm guessing the reason it doesn't reload the page is because you are already on the page when clicking the link. Add a cache buster

<button type="button" onclick="window.location='http://localhost/test.php?param1=A&param2=B&cb=' + new Date().getTime() + '#MyANCHOR';">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top