global javascript variable removed after Touch UI page loads | Community
Skip to main content
New Participant
December 8, 2015
Solved

global javascript variable removed after Touch UI page loads

  • December 8, 2015
  • 7 replies
  • 1958 views

In our javascript we create a global object that is used by many of our components. It seems to work fine when viewing the page without "editor.html" in the path; however when viewed with "editor.html" the variable is created and then removed entirely. So far I have not been able to figure out what is causing our global object to disappear; however the variable _g is present when "editor.html" is in the path and Granite is being used. Is there a setting in our site that is causing Touch UI to remove global objects created by our javascript code? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kunal_Gaba_

I was able to figure out the root cause of your issue. When you open the page for editing with "editor.html" then AEM includes the page content inside an iframe.The iframe is contained inside the child window object of the main page. The parent window object includes all authoring controls like editing toolbar on the top and other elements required for authoring. 

And when you access the page without the "editor.html" in the URL then there is no iframe and the page contents are part of the main window object. So it is an issue of scoping of the variable. You declared the global variable inside the iframe window and it will not be accessible outside the iframe window to the parent window object. 

You need to declare your variable such a way that it is accessible to both child and parent windows- 

//Example //Check if current window is not an iframe. if(self==top) {            _varName = window._varName || {};     } else {            _varName = window._varName || {};           window.parent._varName = _varName;     }

7 replies

Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Participant
December 9, 2015

I was able to figure out the root cause of your issue. When you open the page for editing with "editor.html" then AEM includes the page content inside an iframe.The iframe is contained inside the child window object of the main page. The parent window object includes all authoring controls like editing toolbar on the top and other elements required for authoring. 

And when you access the page without the "editor.html" in the URL then there is no iframe and the page contents are part of the main window object. So it is an issue of scoping of the variable. You declared the global variable inside the iframe window and it will not be accessible outside the iframe window to the parent window object. 

You need to declare your variable such a way that it is accessible to both child and parent windows- 

//Example //Check if current window is not an iframe. if(self==top) {            _varName = window._varName || {};     } else {            _varName = window._varName || {};           window.parent._varName = _varName;     }
New Participant
December 9, 2015

_varName = window._varName || {}

 

the object exists once it's declared, but it will go away afterward. this does not happen when viewing the normal page without editor.html

Kunal_Gaba_
New Participant
December 9, 2015

Can you share your code where you have declared the global variable ?   

New Participant
December 9, 2015

This isn't related to my issue, as my bug is not related to Sightly scripting variables. 

kautuk_sahni
Employee
December 9, 2015

Hi 

There is already an issue for Missing Scripting Variables.

Link:- https://docs.adobe.com/docs/en/aem/6-1/release-notes/known-issues.html ( Reference number "CQ-40324" )

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
New Participant
December 8, 2015

It doesn't seem like a naming conflict since the variable is removed completely. I tried creating other variables at the same point where this one is created and those disappear after continuing javascript execution as well. 

Kunal_Gaba_
New Participant
December 8, 2015

May be there is a name conflict when you view the page with "editor.html" in path. Have you tried renaming the variable and test with "editor.html" ?