Hold option key and select the safari drop down menu. Holding the option key will turn the quit command to quit and close all windows. When you re-open then you should be okay. You're stuck in a java script loop.
Another option is to open up your activity monitor in your Utilities folder. Open activity monitor. Go to drop down menu and choose all processes. Look for Safari web content. Click on the Process Name column title to sort listings by this field so they won’t jump around in your view. Click on X button on top to stop that process. Close the window and you should be good.
Another option is:
Press Option-Command-Escape and use the force-quit dialogue to close Safari. In the Finder, hold the Option key and choose Library from the Go menu. Go to the Saved Application State folder in the Library. Locate and remove the folder called “com.apple.Safari.savedState.”
If those don't work there is a terminal command to keep Safari from opening the last window.