Advertisement
CK_Vartas

Klipfolio - Set Variables with Query String

Aug 17th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Klipfolio - Set Variables with Query String
  3.  
  4. var getUrlParameter = function getUrlParameter(sParam) {
  5.     var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  6.         sURLVariables = sPageURL.split('&'),
  7.         sParameterName,
  8.         i;
  9.  
  10.     for (i = 0; i < sURLVariables.length; i++) {
  11.         sParameterName = sURLVariables[i].split('=');
  12.  
  13.         if (sParameterName[0] === sParam) {
  14.             return sParameterName[1] === undefined ? true : sParameterName[1];
  15.         }
  16.     }
  17. };
  18.  
  19. $( document ).ready( function() {
  20.     var PROD = getUrlParameter('prod');
  21.     var BETA = getUrlParameter('beta');
  22.    
  23.     var changeKlipfolioVariable = function changeKlipfolioVariable () {
  24.         if (PROD == true) {
  25.             $("select").val('DataWarehousePROD').change();
  26.             console.log( "Switched variable to PROD" );
  27.             } else if (BETA == true) {
  28.             $("select").val('DataWarehouseBETA').change();
  29.             console.log( "Switched variable to BETA" );
  30.         }
  31.     }
  32.     changeKlipfolioVariable();
  33.     //setTimeout(changeKlipfolioVariable, 5000)
  34.     console.log( "Variables - PROD: " + PROD + " BETA: " + BETA );
  35. });
  36.  
  37.     window.addEventListener('load', function(){
  38.   // Everything has loaded!
  39.   console.log("Everything has loaded!");
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement