Alert Box and History(back)?

I need an alert box before I allow the user to return to the previous page. How can I modify the following code to utilize the history.back(); functionality?

function alertURL(url) {
if(confirm(“Are you sure you want to go to kfc.com?”)){
location=url;
}
}

<a href=“#” onClick=“alertURL(‘http://www.kfc.com’)”>Visit kfc.com</a>

You may have to use window.location or document.location instead of just location.

Mittineaque - Thanks for the response. This is what I tried:

In the header:

function confirmExit() {
check = window.confirm(“Are you sure you want to exit without saving your changes?”);
if (check == true){
location=history.back();
}
}

In the body:

<a href=“#” onClick=“confirmExit()”>Return to Previous Page</a>

I’m sure its a simple syntax error. Can you make any recommendations?

If back() doesn’t work as expected, you can try this.

function goBack()
{
	history.go(-1);
}  

hope this helps. cb

Thanks much!

This should do it:

function goBack()
{
     if (confirm('Are you sure you want to exit without saving your changes?'))
          window.history.back();

     return false;
}
<a href="#" onclick="return goBack()">Go back.</a>

The ‘false’ return value prevents ‘#’ from being added to the history.

Just for info, history.back() has no return value, so it cannot be used in an assignment in the way you did in your example.

Thanks for the suggestions.