简体   繁体   English

Javascript将参数添加到URL

[英]Javascript add parameter to url

This is a javascript/sharepoint question. 这是一个javascript / sharepoint问题。 ps new to programming and this is modifying the current code. ps是编程新手,正在修改当前代码。

I currently have a custom webpart with a 'Add new item' button that links to a template when clicked on. 我目前有一个带有“添加新项”按钮的自定义Web部件,单击该按钮可链接到模板。 The goal is to amend the url of the template to include the title of the page where the webpart came from. 目的是修改模板的URL,以包含WebPart来源的页面的标题。 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. 例如,页面为“测试页面”,测试页面的Web部件带有“添加新项目”,单击“添加新项目”时,它将进入模板页面。 Original URL = testtesttest%test%test%20.aspx?blah= and to add an &'page title' New URL = testtesttest%20test%20test%20.aspx?blah=&testpage. 原始网址= testtesttest%test%test%20.aspx?blah =并添加&'page title'新网址= testtesttest%20test%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? 以下是我发现相信会预先填充某些内容的JavaScript代码,我该如何修改它来修改url?

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 例如$("#url").href($("#url").href()+"?pageTitle="+$('title').text())或您用来打开模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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