Monday, October 01, 2007 9:53 AM
by
bsandeman
Odd Javascript Issue in MOSS Webpart
I am currently trying to modify a computed column to display only the date part of a datetime field. After much fiddling with CAML I have decided that the only way forward is to write a display pattern that creates dynamic Javascript that rewrites a div tag on the page with the correct value.
Code as follows :
<DisplayPattern>
<HTML>
<![CDATA[<script language="javascript">alert("hello");</script>]]>
</HTML>
<HTML>
<![CDATA[<div id="datemodified_]]>
</HTML>
<Field Name="ID"/>
<HTML>
<![CDATA["></div>]]>
</HTML>
<HTML>
<![CDATA[<script language="javascript">function showDateOnly]]>
</HTML>
<Field Name="ID"/>
<HTML>
<![CDATA[(dtStr){dtStr=dtStr.substring(6,16);
var obj=document.getElementById("datemodified_]]>
</HTML>
<Field Name="ID"/>
<HTML>
<![CDATA["); alert(obj); obj.innerHTML=dtStr;}</script>]]>
</HTML>
<HTML>
<![CDATA[<script language="javascript">showDateOnly]]>
</HTML>
<Field Name="ID"/>
<HTML>
<![CDATA[("]]>
</HTML>
<Field Name="Modified"/>
<HTML>
<![CDATA[");</script>]]>
</HTML>
</DisplayPattern>
For some reason this only works in Firefox and not in IE. Copying and pasting the generated HTML and Javascript to a new test HTML document works fine in both browsers. After some looking around it is reported that IE disables Javascript within IFrames which apparently is what MOSS webparts are within.... This seems rather insane to me and if this is true then surely there must be some setting within IE so that you can enable JS within IFrames for trusted sites?? However, I have enabled every possible setting on this browser and it still does not work. argh.
If any kind soul sees this article and knows how to help me I would most appreciate it. If I do find an answer I will blog it.
thanks