PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0.1
GiveWP – Donation Plugin and Fundraising Platform v4.18.0.1
4.18.0.1 4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 All 258 releases
give / src / DonationForms / resources / app / utilities / navigateTop.ts

navigateTop.ts in GiveWP – Donation Plugin and Fundraising Platform 4.18.0.1, at src/DonationForms/resources/app/utilities/navigateTop.ts

37 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import getCurrentFormUrlData from '@givewp/forms/app/utilities/getCurrentFormUrlData';
2
3 /**
4 * Navigate the top-level window. A cross-origin embed cannot always navigate
5 * window.top directly, so fall back to asking the parent page to navigate via
6 * postMessage. The payload is only a URL; the receiving embed script is
7 * responsible for validating it before navigating.
8 *
9 * The message is addressed to the host page's origin, taken from the
10 * origin-url the embed script passed. The URL can carry a gateway approval
11 * token or a receipt key, so it is not broadcast to whatever page happens to
12 * frame the form. Without a usable origin the message is not sent.
13 *
14 * @since 4.17.0
15 */
16 export default function navigateTop(url: string | URL): void {
17 try {
18 window.top.location.assign(url.toString());
19 } catch (e) {
20 const targetOrigin = getHostOrigin();
21
22 if (targetOrigin) {
23 window.parent.postMessage({type: 'givewp-navigate', url: url.toString()}, targetOrigin);
24 }
25 }
26 }
27
28 function getHostOrigin(): string | null {
29 try {
30 const origin = new URL(getCurrentFormUrlData().originUrl).origin;
31
32 return origin === 'null' ? null : origin;
33 } catch (e) {
34 return null;
35 }
36 }
37