문제

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