codethinked (kōdthĭngked) adj. To be consumed by or obsessed with code.

Fun With HTML Script Tags

I was trying to get some work done this evening on a test ASP.NET MVC website and I made what many (or all) would consider to be a rookie mistake. I created a simple form on a page and included JQuery’s javascript files in the page using a tag like this:

<script src="../../Scripts/jquery-1.3.1.min.js" type="text/javascript" />

And when I rendered the page, I ended up with nothing but a white form. Figuring that I had put something funky in the html, I rendered it in Internet Explorer. I got the same white background with no html rendering. My first thought was that something was causing cassini to crash during the request, but I wasn’t getting any errors.

So I switched over to running in IIS (which required an install since I had just switched to Windows 7), but I was still getting the exact same result. I was so confused because even when I included multiple javascript files, I could always see the javascript from the first script tag, but nothing at all after that! Argh! I checked settings, IIS logs, file attributes, permissions, everything… and you know what the problem was? I self-closed the freakin’ tag. Yeah, both Firefox and Internet Explorer totally choke on self closed script tags without saying anything. As soon as I changed the tag to this:

<script src="../../Scripts/jquery-1.3.1.min.js" type="text/javascript"></script>

It started working immediately. In fact, if I had bothered to open it up in Opera, it would have rendered just fine. Interestingly enough, Firefox is okay with self-closing script tags as long as the last script tag is not self closed. Interesting parsing behavior.

So anyways, I know I have come across this error before, and since I once again wasted a ridiculous amount of time on this; I wanted to get this up on my blog. Now I will remember it for the future and hopefully help someone else out in the process. Just don’t make fun of me too bad.

Comments

trackback

Trackback from progg.ru

Забавляемся с тегом Script в HTML

progg.ru

February 17. 2009 00:26

Liam

Happens to all of us at some time. I had the same brain fade just last month and also blogged to help remember Smile

instantdevelopment.blogspot.com/.../...t-tags.html

Liam

February 17. 2009 01:48

Australia
Marwan

it happened to me once and wasted a lot of time.
it is really strange!

Marwan

February 17. 2009 08:12

Tunisia
Justin Etheredge

@Liam I wish I could have found that the other day, but of course google can't find something when you are looking in the wrong place! Smile

@Marwan Yeah, bizarre rendering bug. I wonder why it is hard for browsers to pick up the mistake and display an error.

Justin Etheredge

February 17. 2009 08:48

United States
Paco

I made this mistake too. I run the w3c validator once in a while to see if some more nasty tagging sneaked in my views.

Paco

February 17. 2009 13:44

Netherlands
Jake Scott

This is the worlds suckiest browser bug ever! This has happened to me a few times and I actually solved this problem for another dev on my team the other day!

Jake Scott

February 18. 2009 04:30

New Zealand
G. Andrew Duthie

Been there, done that. You're certainly not alone. Smile

G. Andrew Duthie

March 12. 2009 14:42

United States

Add Comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading