A few methods come to mind:
1) Read the value of the HTTP_REFERER header (usually available but
not always - this is an HTTP protocol thing)
2) Read the Source query string parameter (sometimes available -
this is a SharePoint-specific thing)
3) If you are coming from a location you control, set a query
string parameter as part of the target URL for the page containing the
web part