-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsup.js
More file actions
28 lines (26 loc) · 1.08 KB
/
sup.js
File metadata and controls
28 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
1. Add a hidden form field for each URL parameter you’d like to capture.
The field’s name should match the key of the URL parameter.
2. Include the script on the page(s) where you’d like to use it.
Change queryForm() to queryForm({reset: true}) to reset values upon form submisision.
*/
var queryForm = function(settings){
var reset = settings && settings.reset ? settings.reset : false;
var self = window.location.toString();
var querystring = self.split("?");
if (querystring.length > 1) {
var pairs = querystring[1].split("&");
for (i in pairs) {
var keyval = pairs[i].split("=");
if (reset || sessionStorage.getItem(keyval[0]) === null) {
sessionStorage.setItem(keyval[0], decodeURIComponent(keyval[1]));
}
}
}
var hiddenFields = document.querySelectorAll("input[type=hidden], input[type=text]");
for (var i=0; i<hiddenFields.length; i++) {
var param = sessionStorage.getItem(hiddenFields[i].name);
if (param) document.getElementsByName(hiddenFields[i].name)[0].value = param;
}
}
setTimeout(function(){queryForm();}, 3000);