Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using SharePoint 2010 and I need to place the following JavaScript code on a page to give me time in Rome

<SCRIPT LANGUAGE="JavaScript">

  function GetTime() {
  var dt = new Date();
  var def = dt.getTimezoneOffset()/60;
  var gmt = (dt.getHours() + def);

  var ending = ":" + IfZero(dt.getMinutes());
  var rome =check24(((gmt + 5) > 24) ? ((gmt + 5) - 24) : (gmt + 5));

  document.getElementById("LocalTime2").innerHTML = (IfZero(rome) + ending);
  setTimeout("GetTime()", 1000);
  }
  function IfZero(num) {
    return ((num <= 9) ? ("0" + num) : num);
  }
  function check24(hour) {
    return (hour >= 24) ? hour - 24 : hour;
  }
  //  End -->
  window.onload = GetTime;

 </script>

 <span id="LocalTime2"></span>

Currently I placed it in a CEWP and it does work, but then when I click save my drop down navigations from the menu stop working and I cant edit the page again.

Getting the following error message:

Message: 'SP.Ribbon.PageState.ImportedNativeData.PageState' is null or not an object Line: 2 Char: 79472 Code: 0 URI: http://cpts1-spointdev/_layouts/sp.ribbon.js?rev=F%2BUEJ66rbXzSvpf7nN69wQ%3D%3D

Any idea why this is happening?

Any other work-around that I can try?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Instead of your window.onload try this

_spBodyOnLoadFunctionNames.push("GetTime");

Hope this helps

share|improve this answer
    
Thank you SOOO much Renzo!! –  Etienne Feb 10 '11 at 13:13
    
Glad it worked! :) –  Renzo Feb 10 '11 at 14:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.