Skip to content

Instantly share code, notes, and snippets.

@dougblackjr
Created July 26, 2019 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougblackjr/7a10a370341f4889a7777f6a0764faf5 to your computer and use it in GitHub Desktop.
Save dougblackjr/7a10a370341f4889a7777f6a0764faf5 to your computer and use it in GitHub Desktop.
Script to get the current query string variables and load them into the designated iframe (https://jsfiddle.net/dougblackjr/v41ztjes/4/)
const iframeLoader = {
baseUrl: 'http://interimhh.hrmdirect.com/employment/job-openings.php?search=true&',
queryStrings: [
'dept',
'city',
'state',
'cust_sort1'
],
init: function(id) {
let url = this.baseUrl
let self = this
this.queryStrings.forEach(function(q) {
const a = self.getParameterByName(q)
if(a) {
url += q + '=' + a + '&'
}
})
if(url[url.length - 1] == '&') {
url = url.substring(0, url.length - 1);
}
this.domReady(function() {
document.getElementById(id).src = url
})
},
domReady: function (fn) {
document.addEventListener("DOMContentLoaded", fn);
if (document.readyState === "interactive" || document.readyState === "complete" ) {
fn();
}
},
getParameterByName: function (name) {
url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return '-1';
if (!results[2]) return '-1';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
}
@dougblackjr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment