Search code examples
javascriptexternal

external JavaScript file - statement - date the page was last modified


Within an external JavaScript file, I'm trying create a statement that inserts the date the page was last modified.

Code in my .html file

    <footer>
    <p id="lastMod">Last Modified: </p>
    <script src="myjava.js"></script> 
    </footer>

code in my .js file

document.getElementById("lastMod").innerHTML = document.lastModified;

I'm using Brackets and it's giving me this error message x2 "ERROR: 'document ' is not defined.[no-undef]"


Solution

  • It's a linting error, not a JS error. You need to set eslint-env to browser, that way it will understand that document is to be expected in your environment and not complain.

    Or you can disable linting entirely:

    https://github.com/adobe/brackets/wiki/How-to-Use-Brackets#eslint

    You can hide the ESLint results panel by clicking the close box at the top (the status bar icon will still indicate if ESLint has found problems with either a green checkmark or yellow warning symbol), or you can turn off ESLint completely by unchecking View > Lint Files on Save.