Created
December 19, 2024 16:07
-
-
Save webdevmatics/755b47b1ed55f5af80ff058aaa2717d7 to your computer and use it in GitHub Desktop.
wesdsd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code ensures compatibility with both URLs, handling parameters in both query and hash fragments. | |
(function () { | |
const searchIdKey = 'sid'; | |
const searchTypeKey = 'searchType'; | |
const ridKey = 'rid'; | |
let searchId = ''; | |
let searchType = ''; | |
let recipientId = ''; | |
// Function to parse parameters from hash fragment | |
function getParamsFromHash(hash) { | |
const hashParams = new URLSearchParams(hash.startsWith('#') ? hash.substring(1) : hash); | |
return hashParams; | |
} | |
// Parse query string and hash fragment | |
const urlParams = new URLSearchParams(window.top.location.search); | |
const hashParams = getParamsFromHash(window.top.location.hash); | |
// Function to get a parameter value from both query and hash | |
function getParamValue(key) { | |
return urlParams.get(key) || hashParams.get(key); | |
} | |
// Get recipient ID | |
if (widget.getValue(ridKey)) { | |
console.log('widget input rid=' + widget.get(ridKey)); | |
if (widget.getValue(ridKey).match(/^\d+$/)) { | |
recipientId = widget.getValue(ridKey); | |
sessionStorage.rid = recipientId; | |
} | |
} else if (getParamValue(ridKey)) { | |
if (getParamValue(ridKey).match(/^\d+$/)) { | |
recipientId = getParamValue(ridKey); | |
sessionStorage.rid = recipientId; | |
} | |
} else if (sessionStorage.rid) { | |
recipientId = sessionStorage.rid; | |
} | |
// Get search ID | |
if (widget.getValue(searchIdKey)) { | |
console.log('widget input sid=' + widget.get(searchIdKey)); | |
if (widget.getValue(searchIdKey).match(/^[-\d]+$/)) { | |
searchId = widget.getValue(searchIdKey); | |
sessionStorage.sid = searchId; | |
} | |
} else if (getParamValue(searchIdKey)) { | |
if (getParamValue(searchIdKey).match(/^[-\d]+$/)) { | |
searchId = getParamValue(searchIdKey); | |
sessionStorage.sid = searchId; | |
} | |
if (getParamValue(searchTypeKey)) { | |
if (getParamValue(searchTypeKey).match(/^\d+$/)) { | |
searchType = getParamValue(searchTypeKey); | |
sessionStorage.searchType = searchType; | |
} | |
} else { | |
searchType = ''; | |
sessionStorage.searchType = searchType; | |
} | |
} else if (sessionStorage.sid && sessionStorage.searchType) { | |
searchId = sessionStorage.sid; | |
searchType = sessionStorage.searchType; | |
} | |
// Debug outputs | |
console.log('Recipient ID:', recipientId); | |
console.log('Search ID:', searchId); | |
console.log('Search Type:', searchType); | |
// Initialize widget | |
widget.addEvent('onLoad', function () { | |
"use strict"; | |
buildApplicationFrame({ | |
URLs: { | |
DEV: 'https://static-dev.mktdatalake.3ds.com/marketing_history/index.html', | |
INT: 'https://static-dev.mktdatalake.3ds.com/marketing_history/index.html', | |
QAL: 'https://static-dev.mktdatalake.3ds.com/marketing_history/index.html', | |
PPD: 'https://static-dev.mktdatalake.3ds.com/marketing_history/index.html', | |
PRD: 'https://static-prd.mktdatalake.3ds.com/marketing_history/index.html' | |
}, | |
dsopts: { rid: recipientId, sid: searchId, searchType: searchType } | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment