Issue
This is the call on the HTML:
<script type="text/javascript" src='../js/scripts.js'></script>
And this is the way I'm using to verify it works:
document.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
window.alert('Hello world!');
}
});
On the Home page it works effortlessly, but in that next page it does not work, feels like it's not triggering again to refresh the document that the js is on.
The file structure for this is:
- data
- js
- scripts.js
- pages
- secondPage.html
- js
- homePage.html
I've tried to put the script tag on the bottom, but still no answer from the js file
Solution
The path for scripts.js
on secondPage.html
should be ../js/scripts.js
, since both are in the same folder. (data
)
<script type="text/javascript" src='../js/scripts.js'></script>
Note: but as someone stated in the comments, you should favor referencing via its absolute path. (/data/js/scripts.js
)
Answered By - David Gomes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.