Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curious about peculiar JavaScript issue regarding script tag type attribute

So, my team is using the HTML5 Boilerplate and has the site nearly finished. I want to do a quick JavaScript test to make sure the client can add their own JavaScript if they so desire. I know the type attribute for the script tag is not required when using the HTML5 doctype, but the JavaScript alert doesn't even work when it's used (which is what has me confused as I've built HTML5 sites while using the type attribute in the script tag.

What works:

    <script>        
      alert("HELP");        
    </script>

What doesn't work:

    <script type="text/javascript">     
      alert("HELP");        
    </script>

Can anyone explain what's going on? This DOES work for other HTML5 based websites...

***Tested with Firefox 12 on Ubuntu 12.04

Thanks guys.

P.S. It's not going to make or break the site, is not very important, etc. I was just wondering why this problem exists.

EDIT

Here's a link to a publically hosted page that WORKS.

http://illinois.edu/1500/index.html

Why does it not work on my local box (shakes head)...?

like image 825
Minja Avatar asked Oct 23 '22 23:10

Minja


1 Answers

Both versions are correct and should work. Either there's a problem in your code like a missing tag or more likely you've checked the "Prevent this page from creating aditional dialogs" checkbox.

Replace your alerts with this and try it out in Chrome:

<script type="text/javascript">
console.log('HELP');
</script>
<script>
console.log('HELP');
</script>

Now run the page in Chrome, press F12 go to Console and see if the messages pop up

like image 150
Valentin Avatar answered Nov 15 '22 06:11

Valentin