473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Everything works but IE

I have this piece of code on a page footer;

<script type="text/javascript">
//<![CDATA[
<!--
if (Date.parse(document.lastModified) 0) {
var last = new Date(document.lastModified);
document.write(last.toLocaleString());
}
-->
//]]>
</script>

It displays the last modified date perfectly in every browser I test it
on - except IE, where it does nothing.
(To specify - it works on Firefox on Windows and on Firefox, Safari and
Camino on Mac. It fails on IE on Windows. They're all I have.)

Can someone please tell me why?

TIA
Alex
Jul 26 '06 #1
6 1490
Can someone please tell me why?
>
Apprently IE has trouble with the CDATA elements. Unless its vitally
important I would just remove it. The problem is that IE expects <!--
immidiatly after <script>, if not it'll try to interpret it as a
statement. So:
<!--
//<![CDATA[
if (Date.parse(document.lastModified) 0) {
var last = new Date(document.lastModified);
document.write(last.toLocaleString());
}
//]]>
-->

would work, but I doubt if it is valid XHTML.

Vincent
Jul 26 '06 #2
Vincent van Beveren wrote:
<snip>
<!--
//<![CDATA[
<snip>
//]]>
-->

would work, but I doubt if it is valid XHTML.
Why not? Comments are valid in XHTML. Of course the fact that XML
parsers are allowed to remove comments means that the entire script may
never be seen if the document is interpreted as XHTML. Fortunately the
odds are that this document is designed to be interpreted as HTML only,
and the CDATA markers are just another mystical incantation.

Richard.

Jul 26 '06 #3
Vincent van Beveren said the following on 7/26/2006 7:20 AM:
>Can someone please tell me why?

Apprently IE has trouble with the CDATA elements.
No, it has problems with syntax errors.
Unless its vitally important I would just remove it.
Yes, indeed.
The problem is that IE expects <!-- immidiatly after <script>,
No, it doesn't expect <!-- and it never has. If it sees it, it ignores
it. If it doesn't, then it moves on.
if not it'll try to interpret it as a statement.
Wrong. The first statement was //<![CDATA[ which it properly interprets
as a comment line.

So:
<!--
//<![CDATA[
if (Date.parse(document.lastModified) 0) {
var last = new Date(document.lastModified);
document.write(last.toLocaleString());
}
//]]>
Look at the original code and the line before your last was --which is
a syntax error and IE balks on *that* error, not the CDATA.
would work, but I doubt if it is valid XHTML.
Yes, because you corrected the syntax error. And with regards to IE, it
doesn't matter if it is valid XHTML or not as IE doesn't have a clue
what XHTML is.

<script type="text/javascript">
//<![CDATA[
if (Date.parse(document.lastModified) 0) {
var last = new Date(document.lastModified);
document.write(last.toLocaleString());
}
//]]>
</script>
No opening <!-- and it does what's wanted in IE.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 26 '06 #4
Vincent van Beveren said the following on 26/07/2006 12:20:
>Can someone please tell me why?

Apprently IE has trouble with the CDATA elements. Unless its vitally
important I would just remove it. The problem is that IE expects <!--
immidiatly after <script>, if not it'll try to interpret it as a
statement.
Vincent,

Thanks. I tried switching the <!-- to before the CDATA (and similarly
the end tags) and it works in IE, but incorrectly in the others.

Odd thing is that there's other script code using the CDATA element that
does seem to work across the board.

Oh well.
Alex
Jul 26 '06 #5
No opening <!-- and it does what's wanted in IE.
.... and in the others.

Thanks.
Alex
Jul 26 '06 #6
JRS: In article <hU*****************@fe3.news.blueyonder.co.uk>, dated
Wed, 26 Jul 2006 10:57:17 remote, seen in news:comp.lang.javascript, A
Browne <cl**@spam.fritter.glasgowrowingclub.orgposted :
>if (Date.parse(document.lastModified) 0) {
var last = new Date(document.lastModified);
document.write(last.toLocaleString());
}

That code does not write in IE4 - but maybe that's correct. Executing
in local master of <URL:http://www.merlyn.demon.co.uk/js-quick.htm>,

document.lastModified 07/24/06 16:48:28 FFF & Y2k, otherwise OK

Date.parse(document.lastModified) -2002003892000

06 is interpreted as 1906, before Epoch, hence negative answer; hence
rest ignored. The code does what it should do for me.

It's silly to throw away the Date.parse result, since it is an ideal
argument for new Date - why do string-to-number conversion twice?

OTOH you could drop the Date.parse and use new Date() there ;

if ((D = new Date(document.lastModified))>1e12)
document.write(D.toLocaleString());

which works for me apart from the Y2k error and the misfortune that
toLocaleString() incorrectly gives me an FFF date.

The 1e12 corresponds to 2001-09-09 01:46:40 UTC; it seems safe to assume
that any page you code in future will be coded after that.
Check, as I did, your code piece by piece, starting with the
lastModified string itself.

Read the newsgroup FAQ. Then re-read 4.30 & follow link.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: xeys_00 | last post by:
I posted a article earlier pertaining programming for my boss. Now I am gonna ask a question about programming for myself. I just finished my first C++ Class. Next semester is a class on...
1
by: John Milano | last post by:
I have everything set up with SQL Server 2000 and Outlook 2000 and the procedure works fine but the message sits in my inbox. When it open the e-mail it says this message has not been sent. I...
1
by: Richard P | last post by:
I've feel that I have tried everything possible but I still cannot get my code to work in both netscape version 6 and IE. My Javascript is in XSL files but this should not matter. I am using...
56
by: john bailo | last post by:
I just installed mono from ximian on my redHat 9 workstation and wrote a simple program from the interesting book ado.net in c# by Mahesh Chand. mono is fun ( is there ado for linux ? ...
0
by: tom mccurdy | last post by:
Greetings, There has been a new site created www.quantumninja.com/toe that is to be used as a resource for people researching the theory of everything. Please join the community then use what is...
14
by: VMI | last post by:
Everytime I open my machine's MSDN and look for a subject, when I double-click on anything, I get "The page cannot be displayed" . What's wrong?
4
by: Amil Hanish | last post by:
Don't reply to this unless you know what you are talking about. Installed brand spanking new 2003 Server. Configured to be application server. Then installed Visual Studio .NET. Copied over...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
13
by: LC's No-Spam Newsreading account | last post by:
I have happily lived for 15 years (our first web server started in 1993) without CSS, but I now decided to learn and experiment with it. My personal preference has always been that the width of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.