Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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!!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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



Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

@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. 

Avatar

Level 2

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.

Avatar

Level 2

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 

 

 

Avatar

Correct answer by
Community Advisor

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



Arun Patidar