Last active
July 14, 2018 11:21
-
-
Save acoyfellow/36e0f2cdfe51f5a01c922dd164eaefcf to your computer and use it in GitHub Desktop.
For trial sales page. Will inject + lock down any form field that is sent in through the URL (by the input ID)
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
<script> | |
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
}; | |
function createCookie(name, value, days) { | |
var expires; | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
expires = "; expires=" + date.toGMTString(); | |
}else{ | |
expires = ""; | |
}; | |
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; | |
}; | |
jQuery(document).ready(function () { | |
document.querySelectorAll('input').forEach(function(input){ | |
if(input.id && getParameterByName(input.id)){ | |
jQuery('#'+input.id).val(getParameterByName(input.id)); | |
jQuery('#'+input.id).prop('disabled', true); | |
}; | |
}); | |
//if affiliate in url, set to cookies | |
var affiliate = getParameterByName('affiliate'); | |
if(affiliate){ | |
createCookie('affiliate', affiliate, 30); | |
}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment