I have a question about Gedit. I am trying to learn JavaScript. I went to http://www.w3schools.com/js/ and tried the Date and Time example.

Date and Time example code:
Source: http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst

<!DOCTYPE html>

<h1>My First JavaScript</h1>

<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>

<p id="demo"></p>


After a while I copied and pasted the script into Gedit and found that it didn't work the way that it did on the W3Schools website. I am able to see something in the browser, but it does nothing when I click the button. Here is a screenshot of what I see:


The pop-up blocker is off, and I don't know what else to do. Are there some plugins that I could use to change this? I don't need anything fancy, I really like Gedit for the most part, I would just like to be able to use it for all my coding needs. All I have learned so far is HTML and CSS.

  • You mean it doesn't color/highlight in the same way? – UniversallyUniqueID Jul 26 '16 at 11:53
  • No the button is there but it has no function. On the website it will provide a date and time when clicked. But it does nothing when I copy it into gedit. – BJsgoodlife Jul 26 '16 at 11:57
  • 1
    Tip: if you're going to learn javascript, you might enjoy the website JSFiddle. It's an online editor for JS, HTML and CSS which allows you to experiment with these languages from a single interface. Your code example would look like this in JSFiddle: jsfiddle.net/vnaaprmd – marcvangend Jul 26 '16 at 15:34
  • 2
    As a public service, I would like to point out that W3Schools has a reputation for not always being of the highest quality. It's a lot better than it used to be, but the reference material at developer.mozilla.org/en-US may be more reliable and up to date. – IMSoP Jul 26 '16 at 17:12
  • From your question and comments, this appears to be a web development question (and a massive amount of confusion as to how web pages work), which is not very well suited here. gedit has nothing to do with your problem. – Matthew Read Jul 26 '16 at 19:18

From the comments:

No the button is there but it has no function. On the website it will provide a date and time when clicked. But it does nothing when I copy it into gedit.

Gedit is a text editor. It can edit text (and source code, etc.). To run the code, save it with a .html (for example, as datetime.html) because this is HTML code.

Then double-click the resulting HTML file to open (and thus run) it in your browser of choice (Firefox, Chromium, Chrome etc.).

As to why:

On the website it will provide a date and time when clicked.

Assuming you mean this, http://i.imgur.com/HZ2x975.png

it is because the thing in the screenshot is not an editor. It is the result.

If you want an editor that also provides the result as a preview, try Atom (there may be others). Write HTML in it and press Ctrl+Shift+M.

| improve this answer | |
  • Perhaps I am asking the wrong question. Your comment is correct, you have to save it to a .html file and double click it, but this has been done already with no success. – BJsgoodlife Jul 26 '16 at 12:44
  • @BJsgoodlife Can you provide screenshots? – UniversallyUniqueID Jul 26 '16 at 12:49
  • @BJsgoodlife Also see the note in the_velour_fog's answer – UniversallyUniqueID Jul 26 '16 at 12:51
  • @BJsgoodlife Look at the JS console output. – UniversallyUniqueID Jul 26 '16 at 13:07

you need to

  • copy the script into gedit then
  • save the code as a file , then
  • load the file in the browser,

Ctrl + o is the shortcut to open a file directly from a browser.
Note: for security reasons browsers sometimes won't allow direct execution of javascript from local files. Because the browser expects it should have been served by a webserver.

| improve this answer | |
  • 1
    I think that last "Note:" is probably the actual answer. I've been stung by this myself, trying to play around with JS Canvas stuff, and had a total facepalm moment when I realised. – IMSoP Jul 26 '16 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.