0

Why is the ext js file not loading?

<html> <head>NEW PAGE WITH JAVASCRIPT</head> <body> <script type="text/javascript" src="demopage.js"> </script> </body> </html> this is the code but for some reason the js file is not popping up when i run the doc

1st Feb 2017, 7:47 AM
Glenn Bennett
Glenn Bennett - avatar
11 Answers
+ 3
Try putting it inside <head></head>?
1st Feb 2017, 7:50 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 3
@Cheeze: Put the script in the <head> can just bring more difficulties ( DOM not loaded when JS script start ) ;) @Glenn Bennett: Don't you have anything else in the <body> or is this just an extract? You can try to put the <script></script> at the very bottom end of the <body>, to be sure that you don't need access to a DOM element, before it would be available... Else: - Is the 'demopage.js' file in the same directory as your html source code? - Are you trying to link it inside a code playground web document? ( linked documents -- css, js, images, and so on -- must to be hosting anywhere on internet and cannot be accessed localy )
1st Feb 2017, 8:08 AM
visph
visph - avatar
+ 2
@visph Yes, I have a feeling that the .js is not in the same directory.
1st Feb 2017, 8:08 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
Not: need to be inside <body> ( or <head>, but don't work outside these two )
1st Feb 2017, 8:23 AM
visph
visph - avatar
+ 2
also, can you post the complete code? or a link to it? html and js, to see how they ( should ) interract?
1st Feb 2017, 8:25 AM
visph
visph - avatar
+ 2
Well, the mistake is in your js file: you need to remove all html tags ( including <script> and </script> ), to keep only script content ^^
1st Feb 2017, 8:31 AM
visph
visph - avatar
0
the .html and the.js file are in the same folder
1st Feb 2017, 8:20 AM
Glenn Bennett
Glenn Bennett - avatar
0
would i need to put it outside the body tags ar the bottom
1st Feb 2017, 8:22 AM
Glenn Bennett
Glenn Bennett - avatar
0
also i am using a text editor app and then viewing it through a browser
1st Feb 2017, 8:23 AM
Glenn Bennett
Glenn Bennett - avatar
0
// demo.html doc <html> <head>NEW PAGE WITH JAVASCRIPT </head> <body> this is the body part of my page <script type="text/javascript" src="demopage.js"> </script> </body> </html> //demopage.js page <html> <head> <script type="text/javascript"> alert("this is an alert box") </script> </head> <body> </body> </html> these are my two pages
1st Feb 2017, 8:29 AM
Glenn Bennett
Glenn Bennett - avatar
0
hey thanks alot it works now lol
1st Feb 2017, 8:33 AM
Glenn Bennett
Glenn Bennett - avatar