I want to add an anchor link in a document library to redirect to another page. How can I do this? The anchor link is:

<a onclick="javascript:location.href='UploadDocuments.aspx' + location.search">Save</a>

  • 1
    You want it in Dispform or in Allitems?
    – XristosK
    Commented Apr 5, 2016 at 9:42
  • I want to add this anchor link in Allitems.aspx Page. how can I do this please help me. thanks Commented Apr 5, 2016 at 16:04
  • When I am using this link in calculate column syntax error has occurs . what syntax need to add this- <a onclick="javascript:location.href='UploadDocuments.aspx' + location.search">Save</a> link Commented Apr 5, 2016 at 16:05

3 Answers 3


When used in a Calculated Column Formula (set tot datatype=Number/DateTime so it outputs as HTML in A View (and View only)) you have to escape the "(double quote) properly:

="<a onclick=""javascript:location.href='UploadDocuments.aspx' + location.search"">Save</a>"
  • Link is working fine and redirect to another page using above formula but SPHostUrl is not passed to redirect page using "location.search". What may be reason for that ? Commented Apr 8, 2016 at 11:56
  • I copied your code; Does it require a ? to specify location.search as parameter maybe... Commented Apr 8, 2016 at 18:02
  • I have try ? in to specify location.search as parameter but it redirect to target page but SPHost Url is not passes still. please give me another solution for this. Commented Apr 12, 2016 at 16:08
  • Forget all the SharePoint stuff; first get your URL right Commented Apr 12, 2016 at 18:51

Consider using Client Side Rendering and JSLinks. Sample code can be found here


You can use approach of using calculated column and achieve your functionality..

Look into this blog, this will provide you all you need to create hyperlink using Caluclated Column on List View.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.