A much better bet is to perform the check server-side, before the page is served. Most server-side scripting languages give access to the referring url, which is included in each HTTP request. In php for example, you can test $_SERVER. If this url is not the one(s) you expect, then you can forward to an error page or whatever you want.
I have never needed to do this but far as I know the server-side approach should be reliable. Maybe someone out there has first hand experience.