Trying to add a list item, specifically the ID into a url in the DispForm.aspx. The customer does not want the ID displayed. I got the link in the display form, I figured out how to split out the ID: I just don't know how to add it or append it to the URL as a querystring. Here is what I have...again, I got the ID, I just need to add it to the .aspx?ID=XX portion in the a href:

<script src="/siteassets/jsLib/jquery-3.3.1.min.js" type="text/javascript"></script>
<script type="text/javascript">

    var a=window.location.href;
    var b=a.split("?")[1];
    var c=b.split("&")[0];
    var d=c.split("=")[1];
    //how do I get "d" in "XX" below?    
<a href="/siteassets/printpreview.aspx?ID=XX" target="_blank">Print Preview</a>


1 Answer 1


No need to split the url in Sharepoint. Just use the Sharepoint built-in function var urlParam = GetUrlKeyValue("NAME_OF_YOUR_URL_PARAMETER") supposing that the page url is something like page.aspx?NAME_OF_YOUR_URL_PARAMETER=1. Then in your HTML you can build a link like:

<a href="#" onclick="window.location='/siteassets/printpreview.aspx?ID=' + urlParam" target="_blank">Print Preview</a>
  • Thanks @steve-t. Your solution worked for me. I did have to change the "a href" to a document.write . For some reason the "a href" opened a separate tab but the focus was on the originating page and not the "target_blank" page.
    – adams-j
    Mar 29, 2019 at 12:47

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.