简体   繁体   中英

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.

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.

The HTML looks like this

<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.

From what I've read I think it is possible to add that query string to the popup URL using JavaScript.

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?

I really appreciate any insight anyone could pass my way. Many Thanks, Alex

I do this using 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:

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.

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