I have a popover that appears on a page after a user clicks a link. When the user then clicks the button in the popover, it does some Javascript that I need to still happen, and then redirects the user to another page. I'm trying to interrupt that redirect, and have the user go to a separate page, but nothing I'm trying seems to work.
If I do the redirect right away, it works, but the rest of the Javascript I need to run doesn't get executed. The same with preventDefault, that seems to prevent the other Javascript from happening that I need to still happen. I also tried using:
$(".specialImg").click(function () { window.onbeforeunload = function () { window.location.href = "https://example.com"; }; }); But the original redirect still happens.
Anyone have any ideas on how I can accomplish this? I have Javascript and jQuery at my disposal. I should mention I'm trying to do this through Optimizely, so I can't edit the code that's executing directly.
preventDefaultjust prevents the normal action of user interface elements, it has no effect on Javascript actions.beforeunloadisn't allowed to do a redirect. All it can do is return a string, which may be shown in the "Do you really want to leave the page?" prompt.