This question/comment is a bit of an overlap with the recent thread here (How to prevent browser message "Leaving site? Changes you made may not be saved."?), but I’m creating a new post about this as I also have a need to defeat the “Leave Site?” dialog and there seems to be no workaround at present.
I’ll be filing a bug report / request for enhancement around this, but wanted to leave a post here for additional detail and commentary.
The issue and my use case is as follows: My app creates embeddable widgets that my users can host on their own sites in an iFrame. This all works swimmingly. However, I am trying to add a feature such that users can have a custom redirect URL that can be loaded in response to certain actions in my widgets.
For example, to enable conversion tracking, I allow users to enter a custom URL that can be loaded after a site visitor submits a booking inquiry (that is, the visitor will be redirected to that custom URL). There are two possible ways to do this – both of which I need to support:
-
Load the custom URL into the current container – the iFrame itself. This can be done successfully and silently without triggering the “Leave Site” dialog, by executing the workflow action “Open an External Website”. However, case 2 cannot be made to work silently…
-
Load the custom URL into the current container’s parent – that is into the window/tab that hosts my embedded iFrame. This can be accomplished using some JavaScript like
parent.window.location.replace("redirectURL");
And, in fact, Bubble will redirect to that URL, but first it pops up the “Leave Site?” dialog. Like so:
This will happen whether or not the user is logged in or not. It will also happen whether the widget is on its own page (not hosted in an iFrame) or hosted in an an iFrame. Like so:
What I need to do is disable or intercept the “Leave Site?” dialog in these cases, but there seems to be no way to do that. I’ve tried many workarounds, including decoupling the redirect from any other workflow steps. (For example, simply having the redirect action in its own Custom Event that listens for a custom state being “yes”.)
It looks to me like this is one of those “unanticipated use case” things more than a bug, but there are valid use cases (like this one) for being able to suppress the “Leave Site?” dialog.
@Bubble team: Is there a way to suppress this dialog programmatically?