title: Change page using a button in SP2010, strange behaviour
body: <p>I'm trying to do something in Sharepoint 2010 that ought to be very simple, create a button that changes page (to a "create new item" form as it happens).</p>
  
  <p>I set up a Content Editor Webpart and put a button in it (not in a form, because in Sharepoint the whole page is a form) with an "onclick" handler that changed the windows.location.href.</p>
  
  <p>In 2010 the CEWP fights you a bit when you try to enter non-trivial HTML, it keeps escaping characters like "&amp;" which can be a real pain. However in the end I got the right content entered.</p>
  
  <p>It didn't work (the page just refreshed itself without changing URL). By checking on StackOverflow I found some recommendations for a more robust form for the CEWP content, which ended up as-</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function submit_rec(){
         window.location.href = "&lt;my server root URL&gt;/Lists/Rec/NewForm.aspx";
         return;
      }
      &lt;/script&gt;
  &lt;button onclick="javascript:return submit_rec();return false"/&gt;Submit a Recommendation&lt;/button&gt;
  </code></pre>
  
  <p>Here's the strange part.</p>
  
  <p>If I use Firebug and put a breakpoint in the submit_rec() function this works fine. But without a breakpoint, it goes back to the behaviour of always returning to the current page.</p>
  
  <p>It seems there's a timing issue, or Sharepoint is taking control after my URL starts to load, and reloads the original page again!</p>
  
  <p>Anyone seen this before and found a solution?</p>
  
  <p>Ideas and suggestions woudl be much appreciated.</p>
  
  <p>Regards: colin_e</p>