简体   繁体   English

使用 JavaScript 向 URL 添加/附加查询字符串

[英]Using JavaScript to add/append a query string to URL

I use the DNN CMS platform and am utilizing a module called ActionForm to create forms from a company called DNNSharp.我使用 DNN CMS 平台,并利用一个名为 ActionForm 的模块从一家名为 DNNSharp 的公司创建表单。

There is an option in this module to display a form in a popup however I cannot pass a query string to the popup URL using this method.此模块中有一个选项可以在弹出窗口中显示表单,但是我无法使用此方法将查询字符串传递给弹出 URL。

The HTML looks like this HTML 看起来像这样

<a href="javascript: showFormPopup1163();">Link Title</a>

Now when I add ?mystring=[mytoken] to the end of the href attribute it stops the link from working.现在,当我将 ?mystring=[mytoken] 添加到 href 属性的末尾时,它会阻止链接工作。

From what I've read I think it is possible to add that query string to the popup URL using JavaScript.从我读过的内容来看,我认为可以使用 JavaScript 将该查询字符串添加到弹出 URL 中。

I've read the following topic but don't know if that is the proper solution for my situation or how I would implement it?我已阅读以下主题,但不知道这是否适合我的情况或我将如何实施?

Add Query-String parameter to static link on click 单击时将查询字符串参数添加到静态链接

Would I just add that code into a tags into my html code?我会将该代码添加到我的 html 代码中的标签中吗?

I really appreciate any insight anyone could pass my way.我真的很感激任何人都可以通过我的方式的见解。 Many Thanks, Alex非常感谢,亚历克斯

I do this using History.js我使用History.js做到这一点

Not sure if ActionForms has a setting for allowing you to include external scripts, but if you can register history.js, you can do something like this:不确定 ActionForms 是否有允许您包含外部脚本的设置,但如果您可以注册 history.js,您可以执行以下操作:

var qsParams = '?mystring=[mytoken]';
var data = '{ mystring: [mytoken] }';
var title = 'Form with token: [mytoken]';
History.pushState(data, title, qsParams);

This will change the url without re-posting the page and will also allow the browser back button to return to the previous url without the querystring change.这将更改 url 而不重新发布页面,并且还允许浏览器后退按钮返回到前一个 url 而不更改查询字符串。

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

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