2

on a page i have a link

<a href="/_l/R/Contact.aspx" id="ctl00_SPLinkbutton1"><span class="ms-splinkbutton-text">Contact</span></a>

I would like to get the current url of the page i'm on and add it to the href.

So if I am on http://mysite.com when I click the link contact above I would go to the page http://mysite.com/_l/R/Contact.aspx?source=http://mysite.com.

Any ideas on how to achieve that in jQuery or JS?

0

3 Answers 3

3

Try this fiddle,

$("#ct100_SPLinkbutton1").click(function(e) {  
  e.preventDefault();
  document.location.href = $(this).attr("href") + "?source=" + document.location;
})

UPDATED

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<a href="/_l/R/Contact.aspx" id="ctl00_SPLinkbutton1">
    <span class="ms-splinkbutton-text">Contact</span>
</a>
<script>
$('a#ctl00_SPLinkbutton1 span').click(function(event) {
    event.preventDefault();
    document.location.href = $(this).attr("href") + "?source=" + document.location;
});
</script>
</body>
</html>

Get this code to your own html page and test, however same code is not working in fiddle, may there is issue in the fiddle in my network.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your help i ended up using thi: jQuery("a#ctl00_SPLinkbutton1").live("click", function(e){ e.preventDefault(); document.location.href = $(this).attr("href") + "?source=" + document.location; });
0
$('#ct100_SPLinkbutton1').click(function() {    
  window.location += $(this).attr('href') + '?source=' + window.location;
}

Comments

0

How about using document.referrer on your next page to get the source url of your previous page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.