Friday, May 6, 2011

Replacing URL in HTML using JQuery

Sometimes if a list is currupted, Allitems.aspx's HTML starts acting weird and we dont want to spend too much time to dig deep into the problem but want a quick fix and endup fixing the HTML. Same goes here.

Following code change the URLs in a page to a predefined URL.
<script type="text/javascript">

 if(typeof jQuery=="undefined")
  var jQsrc="";
  document.write(unescape("%3Cscript src='"+jQsrc+"' type='text/javascript'%3E%3C/script%3E"));

<script type="text/javascript">

$(document).ready(function() {
  //find all hyperlinks in the table holding calendar links and
  //change them to point at the display page instead of the edit page
  var originalUrl = $(this).attr("href");
  var newUrl = originalUrl.replace("OldForm.aspx", "NewForm.aspx");
$(this).attr("href", newUrl);