简体   繁体   中英

Javascript add parameter to url

This is a javascript/sharepoint question. ps new to programming and this is modifying the current code.

I currently have a custom webpart with a 'Add new item' button that links to a template when clicked on. The goal is to amend the url of the template to include the title of the page where the webpart came from. Eg The page is 'Test Page', test page has the webpart with 'Add new item', when clicked on 'Add new item' it takes to template page. Original URL = testtesttest%test%test%20.aspx?blah= and to add an &'page title' New URL = testtesttest%20test%20test%20.aspx?blah=&testpage.

Hope that make sense.

Below is a chunk of javascript code that I've found believe to be prepopulating something, how would I amend this to amend the url too?

function populateList (element, template, data) {
    if (!element) {
         return;
    }

    var templateHtml = '';

    try {
         var summaryTemplate = _.template(template);

         templateHtml = summaryTemplate ({ items: data });
    } catch (e) {
         templatedHtml = 'Template failed';
    }
    $(element).html(templateHtml);
}

On Page load, you should be easily able manipulate the Add Item url. for eg $("#url").href($("#url").href()+"?pageTitle="+$('title').text()) or whatever function you are using to open the template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM