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.

有帮助吗?

解决方案

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';">
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top