Possible Duplicate:
Why don't self-closing script tags work?
I just found a weired behavior with the script tag in HTML.
I web server is nginx, and I used FAST CGI and PHP5. I have a page.html, which looks like this:
<html>
<body>
<!-- <?php echo 'i am going to add php code here'; ?> -->
<script type="text/javascript" src="./my/javascript1.js" />
<script type="text/javascript" src="./my/javascript2.js" />
</body>
</html>
If this page is served directly from the web server, the java script works well. But if it passed to PHP5, it seems only the first java script tag is executed. But if I change the script block into:
<script type="text/javascript" src="./my/javascript1.js"></script>
<script type="text/javascript" src="./my/javascript2.js"></script>
Everything works again. Noticed how the tags are closed? Yeah, that is why I am asking here. What is the difference? They are supposed to have the same function/meaning. Besides, the output HTML that my web browser (Chrome/IE9) received are the same, but why treated differently?
If you're unsure about how you want to proceed, you can go to the Scripts list and duplicate the file in question. The duplicate file will not be synched, and therefore it will retain your changes.
An HTML page can contain multiple <script> tags in the <head> or <body> tag. The browser executes all the script tags, starting from the first script tag from the beginning.
The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
There are two main types of scripting languages: server-side and client-side.
The script tag needs a separate closing tag to be valid code. See http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1
Some browsers will accept the self closing tag, others wont, and the HTML version that you are using also affects the result. There are not self closing tags unless you use XHTML.
Passing the file through the PHP engine should not change the result, but it's possible that it makes an attempt to correct the incorrect script tags. You should view the source in the browser to see if the tags has been changed.
The script
tag is required to have a closing tag, even if it uses the src
attribute. Avoiding it causes undesired behaviours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With