cancel
Showing results for 
Search instead for 
Did you mean: 

Why cannot access Javascript native objects

ebuild
Champ on-the-rise
Champ on-the-rise
I would like to use the firefox console in one of my script deployed in Alfresco (console.log) but figured out that I cannot even use "window" methods like alert(),
[javascript]
Failure: Failed to execute script 'workspace://SpacesStore/f922aad6-4137-41e7-99d0-a2d9f7d71f47': 05150412 ReferenceError: "alert" is not defined. (workspace://SpacesStore/f922aad6-4137-41e7-99d0-a2d9f7d71f47#46)
[/javascript]
1 REPLY 1

afaust
Legendary Innovator
Legendary Innovator
Hello,

you need to understand the difference of client-side and server-side JavaScript. Only client-side JavasScript which is executed by your browser will have access to the Firefox console and "windows" object + functions. The JavaScript you tried to execute is executed on the server-side in a different JavaScript engine. As a result, browser-related API is NOT available and you cannot write to your browser console.
This <a href="http://stackoverflow.com/questions/22061380/repository-tier-vs-web-tier-vs-server-side-vs-client-sid...">StackOverflow question + answer</a> gives a few pointers on the differences of the different JavaScript tiers that you may develop for in the context of Alfresco. The <a href="http://docs.alfresco.com/5.1/concepts/API-JS-intro.html">documentation</a> provides information about the JavaScript API of the Repository-tier, where your script ran.

Regards
Axel