HTMX HX-Redirect can be used to do a client-side redirect to a new location

Description

New in version 0.4.0: htmx 0.4.0 (2020-11-16)

Can be used to do a client-side redirect to a new location.

Examples

open the pdf in a new tab? yes exactly that

htmx.js source code

 1     function handleAjaxResponse(elt, responseInfo) {
 2         var xhr = responseInfo.xhr;
 3         var target = responseInfo.target;
 4
 5         if (!triggerEvent(elt, 'htmx:beforeOnLoad', responseInfo)) return;
 6
 7         if (hasHeader(xhr, /HX-Trigger:/i)) {
 8             handleTrigger(xhr, "HX-Trigger", elt);
 9         }
10
11         if (hasHeader(xhr,/HX-Push:/i)) {
12             var pushedUrl = xhr.getResponseHeader("HX-Push");
13         }
14
15         if (hasHeader(xhr, /HX-Redirect:/i)) {
16             window.location.href = xhr.getResponseHeader("HX-Redirect");
17             return;
18         }
19
20         if (hasHeader(xhr,/HX-Refresh:/i)) {
21             if ("true" === xhr.getResponseHeader("HX-Refresh")) {
22                 location.reload();
23                 return;
24             }
25         }