0

I am following ExtJS tutorial and tried creating a new page. It works.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title id='title'>HTML Page setup Tutorial</title>

        <!-- ** CSS ** -->
        <!-- base library -->
        <link rel="stylesheet" type="text/css" href="ext-3.3.1/resources/css/ext-all.css" />

        <!-- overrides to base library -->


        <!-- ** Javascript ** -->
        <!-- ExtJS library: base/adapter -->
        <script type="text/javascript" src="ext-3.3.1/adapter/ext/ext-base.js"></script>
        <!-- ExtJS library: all widgets -->
        <script type="text/javascript" src="ext-3.3.1/ext-all-debug.js"></script>


        <!-- overrides to library -->

        <!-- extensions -->

        <!-- page specific -->

        <script type="text/javascript">
            // Path to the blank image should point to a valid location on your server
            Ext.BLANK_IMAGE_URL = '../../resources/images/default/s.gif';

            Ext.onReady(function () {

                console.info('woohoo!!!');

            }); //end onReady
        </script>

    </head>
    <body>
    </body>
</html>

However, if I change the script tag line to use self closing tag, like following, it doesn't work.

<!-- ExtJS library: base/adapter -->
<script type="text/javascript" src="ext-3.3.1/adapter/ext/ext-base.js"/>

In Firebug, it complains Ext.EventManager is undefined. I have two questions

  1. Is it generally a bad idea to use self-closing tag for script? I have read this post but it sounds to me it's talking about xhtml.

  2. I am trying to learn Javascript. Although I know the way to fix it is to not use self closing tag, I would still like to know why FireFox think Ext.EventManager is undefined?

Community
  • 1
  • 1
Harvey Kwok
  • 11,713
  • 6
  • 37
  • 59

1 Answers1

2
  1. Yes, it's a bad idea. The script tag needs an ending tag, as you can see in the HTML specification - The script element

  2. Different browsers have different ways of handling incorrect code. Each browser tries to make the best of the situation, but they have different opinions about what's best in each situation. One way to handle some of the incorrect code is to ignore it, which is likely the reason why the script is not executed in Firefox.

Besides, as you don't have a doctype tag the page is by default HTML, not XHTML, so you can't use self-closing tags at all.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • Thanks Guffa and thanks to VS.NET, it automatically gives me a self closing `` tag. That's why I ran into this problem. About question number 2, I still don't understand why `Ext.EventManager` is undefined. I did the self closing on `ext-base.js`. So, I would expect it completely ignore `ext-base.js`. It seems it didn't ignore it but tried to process it. While processing `ext-base.js`, it gives me an error `Ext.EventManager is undefefined`. Any idea why? – Harvey Kwok Mar 07 '11 at 07:23