Question

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

Was it helpful?

Solution

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.

OTHER TIPS

Try this

<a href="#" onclick="alert('thankyou.');history.go(-1);return false">Back</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top