How to Access a JS variable in one clientlib to another clientlib | Community
Skip to main content
vineel_k
Level 2
Dec 29, 2022 6:27 PM UTC
Solved

How to Access a JS variable in one clientlib to another clientlib

I have a requirement that there is a 2 Clientlibs:

1)clientlibA ->clientlibA.js

2)clientlibB ->clientlibB.js

clientlibA.js

(function ($, $document, gAuthor) { "use strict"; var sampleText="sample-text-1"; })($, $(document), Granite.author);

How can i access sampleText variable in clientlibB.js

 

 

Thanks in advance!!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Dec 30, 2022 7:44 AM UTC

you can use jQuery Extension Functions, which works as global functions for a request.

Arun Patidar

5 replies

arunpatidar
arunpatidarAccepted solution
New Participant
Dec 30, 2022 7:44 AM UTC

you can use jQuery Extension Functions, which works as global functions for a request.

Translate
Arun Patidar
BrianKasingli
New Participant
Dec 29, 2022 9:21 PM UTC

You can target the Javascript global scope. https://www.w3schools.com/js/js_scope.asp

 

Translate
vineel_k
vineel_kAuthor
Level 2
Dec 30, 2022 5:00 AM UTC

Hi @briankasingli i tried with global variables it is working in same dialog when i come back to another dialog in same page is is getting undefined but i need to access it in another dialog in same page 

 

 

Translate
Himanshu_Singhal
New Participant
Dec 29, 2022 7:02 PM UTC

@vineel_k If both the clientlibs are invoked within the scope of same page then you can use JS window object to set the value and retrieve at another place (in another clientlib)

window.sampleText="sample-text.-1"

You've to make sure about the execution order i.e. clientlib A logic should execute before clientlib B else property value is going to be undefined. 

Translate
vineel_k
vineel_kAuthor
Level 2
Dec 30, 2022 4:53 AM UTC

hi @himanshu_singhal  clientlibA is presented in one dialog and clientlibB presented in another dialog

i tried above window object getting undefined in console

is there any way to access.

Translate