Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

RC2.0 Javascript problem - strange!

My templates include quite a bit of Javascript.  I track views of each article, for instance, and my menu is also Javascript.  I've come across a somewhat annoying problem that took me some time to find and identify because I thought I was doing something wrong.

Given a template with this code in it:

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{$.headline$}</title>
<LINK REL=stylesheet HREF="/schkerke.com.css" TYPE="text/css">
<SCRIPT SRC="/js/ssm.js" language="JavaScript1.2"></SCRIPT>
<SCRIPT SRC="/js/ssmItems.js" language="JavaScript1.2"></SCRIPT>
<!-- PowerPhlogger Code START -->
<script language="JavaScript" type="text/javascript" src="/js/pphlogger.js"></SCRIPT>
<noscript><img alt="" src="http://www.schkerke.com/pphlogger/pphlogger.php?id=schkerke&st=img"></noscript>
<!-- PowerPhlogger Code END -->
</head>

Switch from HTML View to Normal View.  Switch back to HTML View.  You now have:

<LINK REL=stylesheet HREF="/schkerke.com.css" TYPE="text/css">
<SCRIPT SRC="/js/ssm.js" language="JavaScript1.2"></SCRIPT>
<SCRIPT SRC="/js/ssmItems.js" language="JavaScript1.2"></SCRIPT>
<!-- PowerPhlogger Code START -->
<script language="JavaScript" type="text/javascript" src="/js/pphlogger.js"></SCRIPT>
<SCRIPT SRC="/js/ssmItems.js" language="JavaScript1.2"></SCRIPT>
<noscript><img alt="" src="http://www.schkerke.com/pphlogger/pphlogger.php?id=schkerke&st=img"></noscript>
<!-- PowerPhlogger Code END -->
</head>

It doesn't have to be the <head /> of the document either.  I have code similar to

<span class="PostCommentSpan">
<A title={$.CommentPopup$} onclick={$.WindowPopupCode$} href="PTMFOG0000000262.php?id={$.filedDate$}{$.filedTime$}">Post A Comment</A>
(<SCRIPT language="JavaScript" type="text/javascript">commentCounter({$ .filedDate $}{$ .filedTime $})</SCRIPT>)
</span>

When the above two sets of code are in the same template there's a very good chance that the top code will be inserted prior to the <SCRIPT> tag in the bottom code.  This one is sporadic, however.

The top one is not sporadic.  I can reproduce it at any point in time using my templates.

Thanks!

Brian Schkerke
Sunday, August 03, 2003

Heh, that's ugly.

The problem is that the line

<SCRIPT SRC="/js/ssmItems.js" language="JavaScript1.2"></SCRIPT>

gets reproduced when you switch views.

Brian Schkerke
Sunday, August 03, 2003

I noticed the same or simlar behavior when working on my site. In one of my "code fragments" that I use as an include, I have some inline javascript to do an image mouseover.

As long as I stay in HTML only mode, the code is fine. As soon as I switch to Normal mode, make a change, then switch back to HTML mode, my javascript is gone, and the code's been reformated.

Thankfully, the code wasn't nearly as complex as yours (just a mousever and a mouseout).

CRC
Sunday, August 03, 2003

*  Recent Topics

*  Fog Creek Home