title: JS onclick="history.go(-1) only if under my domain
body: <p>I have a Joomla site, and I  have the following problem, I need a "Back to search page" function on my product details page, and I am using this code after some changes according to replies to my initian question:</p>
  
  <pre><code>&lt;br/&gt;&lt;a href="" onclick="if (document.referrer.indexOf(window.location.host) !== -1) alert('true'); { history.go(-1); return false; } else { window.location.href = 'mysite.com.br'; }"&gt;&lt;?php echo JText::_('VOLTAR'); ?&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Now, if a Visitor comes from another site directly to my product page and click this,  he will be redirected to homepage of my site, and this is ok, but if I in a search page of my site, click on a product page and then click on the back to search link, the visitor is also redirected to my homepage, which is not good, it should be redirected to previous page, which was his own search page.</p>
  
  <p>Is there any way to modify this code in order to accomplish something like:</p>
  
  <p>if visitor comes from my search page or from anywhere in my site, by clicking this he will be redirected to the previous page, and if a visitor came from outside of my site, by clicking this he will be redirected to my homepage?</p>