I'm using

history.back(alert("thankyou."))

After a form has been successfully send, it works fine on Safari but on Chrome it doesn't show up the alert

有帮助吗?

解决方案

Your code is working fine in Chrome for me.

history.back(alert("thankyou."))

In the code you provided, what you are doing is calling alert("thankyou.") and then passing the return value of that function (it returns undefined) to history.back as an argument. This function doesn't take any arguments, so anything you pass it is ignored.

This will result in the alert happening, followed by the browser navigating to the previous page in history. It's not possible to alert after calling history.back. Once the browser navigates to another page, code execution of the current page will stop.

You can only alert before the page changes. The method you're using here is non-standard, and I would suggest changing it to this for readability purposes:

alert("thankyou.");
history.back();

Alternatively, you could make your alert happen on the previous page which you are navigating to instead. This would let you trigger the alert after the page redirects.

其他提示

Try this

<a href="#" onclick="alert('thankyou.');history.go(-1);return false">Back</a>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top