SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javacript doesn't work in Firefox

    Hello bros and sis's,

    I'm a newbie. I've got this function that renders the current calendar year in a browser. In IE, the year "2011" shows up, but nothing shows up in Firefox 3.6.17, wonder if someone could help me figure out why and how to fix it.

    Code JavaScript:
    <script type="text/jscript">
    				    var _today = new Date();
    				    var _year = _today.getYear();
    				    if (_year < 200) _year += 1900;
    				    currdate = new Date;
    				    document.write(currdate.getFullYear());
    			   </script>

    Thanks in advance. [Pardon me for the typo in the title of this post.]

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,809
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    getYear() is not Y2K compliant. It will return different results in different browsers for years from 2000 onwards. It should not be used.

    That doesn't explain why the date isn't showing though as it is only the last two lines within that script that are actually being used to display the year in the page. Possibly something elsewhere in the page is interfering.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by TintinAPE View Post
    but nothing shows up in Firefox 3.6.17, wonder if someone could help me figure out why and how to fix it.

    The script type text/jscript is proprietary to Microsoft's Internet Explorer web browser.

    text/javascript is the standard type to use.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,809
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Oops - missed seeing the type was set that way - Opera will also unfortunately allow the JavaScript to be run in that instance.

    Quote Originally Posted by paul_wilkins View Post
    text/javascript is the standard type to use.
    No - the standard type is "application/javascript".

    "text/javascript" is deprecated but has to be used because Internet Explorer doesn't understand the standard one.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by felgall View Post
    No - the standard type is "application/javascript".
    It looks like we have a slight difference of opinion about that. I'm using "standard" according to the definition of "by general consent as a basis of comparison" whereas if we were talking about what is laid down by "the standards" or the JavaScript specifications, then I'm in total agreement with you there.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    I'm just wondering what the first three lines are even for -- since they aren't even used on the page. Though yeah, app/js is what you should use by the spec, but it doesn't actually work any better than text/jscript does -- text/javascript is what should be there if you care about it actually working.

    But then I don't understand why application/javascript would be the appropriate as that's code... uncompiled without an interpreter that's text, NOT an application. Lemme guess it's like the re-re's who call XML a "machine readable format"? (as a machine language coder I take great exception to that)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •