window.history.back()不起作用。

问题描述:

我无法让这个工作。我一直在努力多年。请帮帮我。

I cant get this to work. I have been trying for ages. Please help me.

<script>
function goBack() {
    window.history.back()
}
</script>

<button onclick="goBack()">Go Back</button> 


请看与window.history.back() 不一致:与window.history.back()不一致。

这个

<button type="button" onclick="goBack()">Go Back</button> 

可能就是您要找的东西

正如Kevin B所建议的那样


提交表单,从而导致页面刷新。添加type =button
将防止发生这种情况。

The browser could be interpreting the button as a submit button and submitting the form, thus causing a page refresh. Adding type="button" will prevent that.