Javascript src property not working
It is very simple. Web page source is
<script type="text/javascript" src="/jscript.js"></script> <html><body> <h1>It works</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html> I put js at the very beginning.
in jscript.js, this is:
<script type="text/javascript"> document.write("test text from bill!"); </script> But the text is not displayed. If I embed js in html, it works.
And it is strange that when I directly access jscript.js from a web browser, the content looks like this:
<script type="text/javascript" src="/jscript.js"> </script><script type="text/javascript"> document.write("test text from bill!"); </script> Does anyone help?
You must not include tags in your JavaScript file.
Even if you delete them, your text will be written too early on the page, so I'm not sure if it will be displayed correctly. You are currently writing text in front of <html> .
I'm not sure your <script> location is even valid. In addition, you have excluded the <head> document that is required.
The correct structure of your page for writing to body will be:
<html> <head> </head> <body> <script type="text/javascript" src="/jscript.js"></script> <!-- your script will write the content right here --> <h1>It works</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body> </html>