HTML and Javascript workspace can't access global objects like window or document



Recently I discovered IDE, but right at the start I’ve encountered problem, to which I can’t find solution online. When I try to access global javascript objects like document, after running script I’m getting error document is not defined. For example for simplest code:

I’m getting error:

ReferenceError: window is not defined
Any idea what I could possibly done wrong and how can I fix this?


Where are you trying to access this? If you’re trying it in the preview, open it in a new window and try again?


Here’s how I can reproduce this problem:

  1. click the big plus sign in the dashboard
  2. name the new workspace. Leave it as “public” and “html”
  3. click “create”
  4. open “hello-world.html”
  5. click “Run”. Notice there are no errors.
  6. click “Stop”
  7. cut the contents of the script tag (var myButton… etc) and paste them into a new file called script.js
  8. put “src=script.js” in the tag.
  9. Click Run. Notice the ReferenceError: document is not defined


Ooh. Ooh. Replying to myself. I bet the "document’ is not loaded yet The script tag is being loaded too soon?


the window object does not exist in a cloud 9 workspace environment it is a text editor, not a browser window is an exclusive api to the browser it cannot be accessed within a text editor. Try opening up the Chrome tools in your browser and doing it there to see what I am talking about.