Created
July 26, 2019 17:28
-
-
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/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, ' ')); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FIDDLE HERE: https://jsfiddle.net/dougblackjr/v41ztjes/4/