Malware attack freezes Safari—prevention or detection?
I have run into similar situations. I gather the host DNS name from the url and put a matching line into my /etc/hosts file. The I force quit safari and relaunch.

The line I add to /etc/hosts looks like this:

127.0.0.5        badhost.com


This will redirect all browser requests to the badhost to localhost (the local machine) where the requests timeout. This breaks the javascript that is holding your browser hostage. I'm using 127.0.0.5 (instead of 127.0.0.1) so I can distinguish the bad requests from normal localhost requests with my networking tools.