Help to read/write global variable #290
Unanswered
rtnogueira
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey guys!
Considering the following code that will be executed in Partytown and that needs to read/write a global variable that must be accessible from the main thread, in order for other third-parties can read/write as well?
`<script type="text/partytown">
window.universal_variable = window.universal_variable || {};
window.universal_variable.user = {
geoCountryCode: "PT",
returning: true,
language: "en",
countryId: 000,
countryCode: "GB",
geoCountryId: 000,
geoSubfolder: "/pt",
userSubfolder: "/uk",
isLogged: false,
isBot: false,
checkoutType: 0,
genderId: 0,
wishListQuantity: 0,
tier: null,
isMobile: false,
};
if (window.universal_variable.user) {
var uvUserEvt = document.createEvent("Event");
uvUserEvt.initEvent("universal_variable.user", true, true);
document.dispatchEvent(uvUserEvt);
}
</script>`
Is it possible? What strategy do I need to follow? Anyone can help?
Regards!
Beta Was this translation helpful? Give feedback.
All reactions