Richard Grant Share Posted October 8, 2014 <html> <body> <script language="javascript" type="text/javascript" src="object_.js"> alert("working"); </script> </body> </html> Are we able to execute js like this? Or MUST we do this... <html> <body> <script language="javascript" type="text/javascript" src="object_.js"> </script> <script language="javascript" type="text/javascript"> alert("working"); </script> </body> </html> Link to post Share on other sites
0 night_stalker_z Solution Share Posted October 8, 2014 For the script tag, if you specify the src attribute, it will ignore anything inside it. http://www.w3.org/TR/html5/scripting-1.html#the-script-element 1 Share Link to post Share on other sites
0 spacer Share Posted October 8, 2014 Script blocks are interpreted and executed in-line as they are processed by the browser. So your first example will work just fine. This is also the reason why most large javascript files and script blocks are added at the end of the body rather than the head of the document. The page will fully load and render while the javascript is being processed. Link to post Share on other sites
0 Richard Grant Author Share Posted October 8, 2014 Script blocks are interpreted and executed in-line as they are processed by the browser. So your first example will work just fine. This is also the reason why most large javascript files and script blocks are added at the end of the body rather than the head of the document. The page will fully load and render while the javascript is being processed. That what i thought but the code inside the blocks are not executing. the src link is correct and the console is not outputting any errors. The second example is working fine. Why isnt't the first? Odd stuff here. Link to post Share on other sites
Question
Are we able to execute js like this?
Or MUST we do this...
Link to post
Share on other sites
4 answers to this question
Recommended Posts