Implementing retrival of alert text for onBeforeUnload dialogs.

Fixes issue #7901.