Our site uses a separate shopping cart service. I can customize the HTML for each product. Typically, a user goes to our site and clicks the "buy" button, which goes to the shopping cart product page. There I'd like to put a "Return to shopping" button that will take them back.
I can use an ordinary back button
<form action=""><input type="button" value="Return to shopping" onclick="history.go(-1);return true;"/></form>
which works so long as the product page was accessed from our site. Sometimes, however, the user goes there directly from somewhere else and in that case I'd like the "Return to shopping" button to go instead to "mysite.com/products".
So I'm looking for sample code that will check the value of "history.go(-1)" and, if it contains "mysite.com", goes there; else goes to "mysite.com/products".