Stump the Panel: SharePoint Q&A

Immediate solutions for common SharePoint questions
It is currently Tue Sep 16, 2014 9:25 am

All times are UTC - 5 hours [ DST ]


Forum rules


What you are viewing is an archive of Stump the Panel. It remains for reference purposes. Please post all new questions on NothingButSharePoint.com
https://www.nothingbutsharepoint.com/sites/eusp/Forum



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: jquery append
PostPosted: Tue Nov 02, 2010 4:55 pm 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
I've got this snippet of rendered HTML from the quick launch of the default.aspx page on my site.
Code:
<td style="width:100%;"><a class="zz2_QuickLaunchMenu_1 ms-navitem zz2_QuickLaunchMenu_5" href="/sites/trainingtest/Lists/Courses/NewForm.aspx" style="border-style:none;font-size:1em;">Add new course</a></td>


What I'd like to do is to append a ?Source= current URL. Can I do that with jQuery? I know I could go into the quick launch/navigation menu and configure it as needed, but that isn't dynamic on provisioning like it would be with a jQuery solution.


Top
 Profile  
 
 Post subject: Re: jquery append
PostPosted: Tue Nov 02, 2010 6:24 pm 
Offline
User avatar

Joined: Sat Jan 02, 2010 6:02 pm
Posts: 1035
Location: Silver Spring, MD
Just for you Eric. I put of working out to get this one done... Maybe that's a win-win? :)
Code:
<script type="text/javascript">
$(document).ready(function() {
   $("a[class*='QuickLaunchMenu']").click(function(){
      var curr_URL = document.location.href;
      appendTo_URL = "?Source=" + curr_URL;
      var link_URL = $(this).attr('href');
                //alert(link_URL + appendTo_URL);
      $(this).attr('href', link_URL + appendTo_URL);
   });
});
</script>


This should work. If not, the selector of the anchor tag is wrong and you'll have to tweak it.


Top
 Profile  
 
 Post subject: Re: jquery append
PostPosted: Tue Nov 02, 2010 9:23 pm 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
Perfect, exactly what I was looking for.


Top
 Profile  
 
 Post subject: Re: jquery append
PostPosted: Tue Nov 02, 2010 10:07 pm 
Offline
User avatar

Joined: Sat Jan 02, 2010 6:02 pm
Posts: 1035
Location: Silver Spring, MD
Cool! But you know, I still have to put my jQuery warranty on it! LOL


Top
 Profile  
 
 Post subject: Re: jquery append
PostPosted: Wed Nov 03, 2010 8:10 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
Would it be possible to further select just the NewForm.aspx anchor since there may be more than 1 quick launch item and I wouldn't want to ?Source them all.


Top
 Profile  
 
 Post subject: Re: jquery append
PostPosted: Wed Nov 03, 2010 8:17 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 6:02 pm
Posts: 1035
Location: Silver Spring, MD
I haven't tested this, but as long as NewForm.aspx is in your href, then the selector should look like:
Code:
$("a[href*='NewForm.aspx']").jquery.....


Top
 Profile  
 
 Post subject: Re: jquery append
PostPosted: Wed Nov 03, 2010 8:45 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
Yep, that works too. I'll include both in the script and comment one of the lines out. Then depending on how the Quick Launch is configured, users can easily tweak how they want it to function.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group