Last active
December 26, 2015 21:49
-
-
Save DeskWOW/7218265 to your computer and use it in GitHub Desktop.
Using Sessvars (JavaScript session variables) to send data to your support center and store it within the browser session (so it's still accessible as the user browses your support center) without the use of cookies or multipass.
This file contains 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
// Include the sessvars library | |
<script src="https://desk-customers.s3.amazonaws.com/shared/sessvars.js" type="text/javascript"></script> | |
// This function allows you to read a GET parameter from the URL | |
function getParameterByName(name) { | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), | |
results = regex.exec(location.search); | |
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
// This function populates the page with whatever the value of 'color' sessvar is | |
function popFromSess() { | |
$(".color").html(sessvars.color); | |
$(".animal").html(sessvars.animal); | |
} | |
// On page load, grab the GET parameter and store it as a sessvar, then populate the page with it | |
$(function() { | |
if (getParameterByName("color")) { sessvars.color = getParameterByName("color");} | |
if (getParameterByName("animal")) { sessvars.color = getParameterByName("cow");} | |
popFromSess(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment