Display dynamic URL

May 2, 2014 at 8:56 PM
New to jquery. I'm trying to display a dynamic URL such as - http://domain.com/page.aspx?user=useremailaddress. I've got the following code but cannot get it to display the URL within the content editor web part.

<script src="http://inform.milestoneky.com/JqueryLibraries/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="http://inform.milestoneky.com/JqueryLibraries/jquery.SPServices-2014.01.min.js" type="text/javascript"></script>
<script type="text/javascript"> $(document).ready(function() { var thisUserID = $().SPServices.SPGetCurrentUser({ fieldName: "Email", debug: true }); var link = 'http://test.com/test.aspx?COID=40407&UniqueID=' + thisUserID; }); </script>
May 2, 2014 at 9:38 PM
All you've done so far is construct the href (URL) string. A link in the page would be markup like this:
var url = "<a href='" + link + "'>some text here</a>";
Then you need to put that markup into the page. Maybe something like this:
May 5, 2014 at 12:30 PM
Edited May 5, 2014 at 12:38 PM
OK. I have the following but nothing appears in the content editor web part. <script type="text/javascript"> $(document).ready(function() { var thisUserID = $().SPServices.SPGetCurrentUser({ fieldName: "Email", debug: true }); var link = 'http://test.com/test.aspx?COID=40407&UniqueID=' + thisUserID; var url = "some text here"; $("#myDiv").html(url); }); </script>
May 5, 2014 at 1:22 PM
$("#myDiv") was just my example. You need to put the link into the DOM somewhere.

May 5, 2014 at 3:40 PM

Got it to work. One other question – is there a way to make this dynamic URL appear on the top link bar?

Brandon Buffin
Information Technology

3609 Walden Drive
Lexington, KY 40517
Office - 859-268-1191
Direct - 859-514-3434
Fax - 859-268-9093
[email removed]


May 6, 2014 at 11:42 AM
You will have to examine the DOM and determine how your top link bar is structured. From there, you can construct and append an element similar to the elements already in place. The structure of the top link bar may vary from one SP version to another. SPServices isn't going to help you with this part but jQuery will make it easier to navigate to the desired location and place your content.