I'm talking about a styled dialog, instead of the default 'beforeunload' dialog that can't be styled.
See Facebook:
What is the most unobtrusive way to make this? Preferrable some script that I declare once, and magically always works.
I'm think about something in the line of:
function showCustomDialog()
{
[...]
}
var unfinished = true;
$('a').click(function()
{
if ( unfinished )
{
window.showCustomDialog( { originalUrl: $(this).attr('href') } );
return false;
}
}
But I'm affraid this will break cases where i.e. a <a>
element is used for triggering JS-behaviour, or where JavaScript triggers a window.location.href change.
Is there a better, non-obtrusive way?
Extra note - They also got it working for the back button.
Extra note - Apparently they fall back to the default dialog when it's out of their control.
history.replaceState
. As for the back button, they're probably usingonbeforeunload
to trigger the previous request (breadcrumbs). – Amaty