How to Identify Safari Javascript Alert Dialog using AppleScript?
If you had an alert dialog appearing with an OK button, then this AppleScript code would close it.

tell application "System Events" to tell process "Safari"
    if exists (button "OK" of window 1) then
        click (button "OK" of window 1)
    end if
end tell


You'll likely need to customise this to fit your exact situation. If the alert dialog appears with a title you can all specify that as below.

tell application "System Events" to tell process "Safari"
    if exists (button "OK" of window "Java applet missing") then
        click (button "OK" of window "Java applet missing")
    end if
end tell


Another option would be to identify the alert by using "front window" as in the following example (assuming the alert is the front window).

tell application "System Events" to tell process "Safari"
    if exists (button "OK" of front window) then
        click (button "OK" of front window)
    end if
end tell


Hope this helps.