PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.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 2.3.1 2.3.2 All 256 releases
← All changes | src/DonationForms/resources/app/utilities/getCurrentFormUrlData.js +35 -13 4.15.3 → 4.17.0 View file →
@@ -1,22 +1,39 @@
1 1 /**
2 + * @since 4.17.0 Support cross-origin embeds: guard window.top and window.frameElement access with URL parameter fallbacks.
2 3 * @since 3.22.0 Add locale support
3 4 */
4 5 export default function getCurrentFormUrlData() {
5 - const originUrl = window.top.location.href;
6 + const urlParams = new URLSearchParams(window.location.search);
6 7
7 - const isEmbed = window.frameElement !== null;
8 + let originUrl;
9 + let isCrossOriginEmbed = false;
8 10
11 + try {
12 + originUrl = window.top.location.href;
13 + } catch (e) {
14 + // Cross-origin embed: the parent page URL is unreadable, so use the
15 + // origin-url param passed by the embed script, then the referrer.
16 + isCrossOriginEmbed = true;
17 + originUrl = urlParams.get('origin-url') || document.referrer || window.location.href;
18 + }
19 +
20 + const isEmbed = window.self !== window.top;
21 +
9 22 const getEmbedId = () => {
10 23 if (!isEmbed) {
11 24 return null;
12 25 }
13 26
14 - if (window.frameElement.hasAttribute('data-givewp-embed-id')) {
15 - return window.frameElement.getAttribute('data-givewp-embed-id');
27 + if (window.frameElement) {
28 + if (window.frameElement.hasAttribute('data-givewp-embed-id')) {
29 + return window.frameElement.getAttribute('data-givewp-embed-id');
30 + }
31 +
32 + return window.frameElement.id;
16 33 }
17 34
18 - return window.frameElement.id;
35 + return urlParams.get('embed-id');
19 36 };
20 37
21 38 const getLocale = () => {
22 39 if (!isEmbed) {
@@ -22,24 +39,29 @@
22 39 if (!isEmbed) {
23 40 return null;
24 41 }
25 42
26 - if (window.frameElement.hasAttribute('data-form-locale')) {
27 - return window.frameElement.getAttribute('data-form-locale');
28 - }
43 + if (window.frameElement) {
44 + if (window.frameElement.hasAttribute('data-form-locale')) {
45 + return window.frameElement.getAttribute('data-form-locale');
46 + }
29 47
30 - let locale = '';
31 - if (window.frameElement.src) {
32 - const url = new URL(window.frameElement.src);
33 - locale = url.searchParams.get('locale') || '';
48 + let locale = '';
49 + if (window.frameElement.src) {
50 + const url = new URL(window.frameElement.src);
51 + locale = url.searchParams.get('locale') || '';
52 + }
53 +
54 + return locale;
34 55 }
35 56
36 - return locale;
57 + return urlParams.get('locale') || '';
37 58 };
38 59
39 60 return {
40 61 originUrl,
41 62 isEmbed,
63 + isCrossOriginEmbed,
42 64 embedId: getEmbedId(),
43 65 locale: getLocale(),
44 66 };
45 67 }