From f43973585fbcea76d631249234d7349666c58ac0 Mon Sep 17 00:00:00 2001 From: Amitai Burstein Date: Wed, 10 Jan 2024 14:06:56 +0200 Subject: [PATCH] Allow redirect to external sites if CORS isn't enabled --- lib/IHP/static/helpers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/IHP/static/helpers.js b/lib/IHP/static/helpers.js index 039cea78a..633d181a5 100644 --- a/lib/IHP/static/helpers.js +++ b/lib/IHP/static/helpers.js @@ -296,7 +296,15 @@ window.submitForm = function (form, possibleClickedButton) { 'Content-Type', 'application/x-www-form-urlencoded' ); - request.send(parameters.join('&')); + + try { + request.send(parameters.join('&')); + } catch (e) { + // If the send method throws an exception, redirect to the form action URL. + // This can happen for example if redirecting to an external site, which doesn't have CORS enabled, + // so we can't use Ajax. + window.location.href = url; + } } var buttons = form.getElementsByTagName('button');