Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
js displays differently local vs server on netscape
Old 08-24-2004, 06:48 PM js displays differently local vs server on netscape
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hi all,

I'm wondering if someone might know why the following displays differently when run locally versus when it is run on the host server. It only happens when using Netscape 7; I.E. displays it properly (although in a different form).

I've had the following script on a site for quite some time but recently changed hosts and I have to assume it has something to do with that.

HTML Code:
<SCRIPT LANGUAGE="JavaScript"> 

<!-- Begin
var b = "Page last updated on " + document.lastModified;
var j = b.length-8;
document.writeln("<center>");
document.write(b.substring(j, 0));
document.writeln("</center>");
// End -->

</SCRIPT>
Locally it displays as:
Page last updated on Tuesday, August 3, 2004

But when run from the host server it displays as:
Page last updated on Tue, 03 Aug 2004 23:3

Using I.E. 6, the displays are identical, locally and from the server, except that it displays in the following form:
Page last updated on 08/03/2004

Anyone have any idea why the differences?
Yizit is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-25-2004, 12:36 AM
theJack's Avatar
Experienced Talker

Posts: 46
Trades: 0
The difference is that the "document.lastModified" variable is a field set by the server. My guess is your host server runs some version of linux, while your local is Windows. I would venture that those OSes have different ways to display dates, hence the difference.

I realized this doesn't explain why its the same with IE. Possibly IE automatically converts varying date formats.
__________________
-theJack
theJack is offline
Reply With Quote
View Public Profile Visit theJack's homepage!
 
Old 08-25-2004, 01:13 AM
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Thanks for the explanation. You are absolutely correct. Host is running linux and local is running Windows. Although having the Date Last Modified may be helpful to some visitors, it's not imperative that I display this. Out of curiousity though, would you know if this script can be easily modified or if there is another script that will accomplish the same purpose? As it stands now, it just looks unprofessional.

Again, thanks for your explanation.

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
Old 08-25-2004, 01:42 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Yes, you have to convert the lastModified string into a timestamp via the Date.parse() method, from there it's as if working with the Date object (meaning, you can do getDay(), getYear() etc).

Here's my muckup of a function you can use. Most of the code is defining the Days and Months because Javascript returns numerical numbers instead of words.

HTML Code:
<html>
<head>
<title>Blah</title>
    <script language="javascript">
    function printDate()
    {
        var timestamp;
        var date;
        var info    = new Array();
        var Days    = new Array();
        var Months  = new Array();

        timestamp = Date.parse(document.lastModified);
        if(timestamp == 0)
            return false;

        date = new Date(timestamp);
        
        Days = {
                    0 : "Sunday",
                    1 : "Monday",
                    2 : "Tuesday",
                    3 : "Wednesday",
                    4 : "Thursday",
                    5 : "Friday",
                    6 : "Saturday",
                    7 : "Sunday"
               };
       
        Months = {
                    0   : "January",
                    1   : "February",
                    2   : "March",
                    3   : "April",
                    4   : "May",
                    5   : "June",
                    6   : "July",
                    7   : "August",
                    8   : "September",
                    9   : "October",
                    10  : "November",
                    11  : "December"
                 };

        info = {
                    'day'   : Days[date.getDay()],
                    'date'  : date.getDate(),
                    'month' : Months[date.getMonth()],
                    'year'  : date.getFullYear()
               };

        document.writeln("Last updated on <strong>" + info['day'] + ", " + info['month'] + " " + info['date'] + ", " + info['year'] + "</strong>");
    }
    </script>
</head>
<body>
<script language="javascript">printDate();</script>
</body>
</html>
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 08-25-2004, 02:50 AM
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
OK Chroder - got it. Good approach. Using your method not only fixes the problem but also makes the display identical in both Netscape and IE. I've always preferred Netscape's verbose display as opposed to IE's numeric display and it's a change that's been on my 'I'll get around to it someday' list for quite some time.

So..... 1 down and only 4,583 more items to go and I'll be able to toss my to-do list!

Seriouly though - to both you guys - I appreciate the help!

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to js displays differently local vs server on netscape
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40824 seconds with 12 queries