Created
June 30, 2013 13:31
-
-
Save fadlee/5895152 to your computer and use it in GitHub Desktop.
Javascript Functions
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
//How can I get query string values? | |
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, " ")); | |
} | |
function setCookie(c_name,value,exdays) | |
{ | |
var exdate=new Date(); | |
exdate.setDate(exdate.getDate() + exdays); | |
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); | |
document.cookie=c_name + "=" + c_value; | |
} | |
function getCookie(c_name) | |
{ | |
var c_value = document.cookie; | |
var c_start = c_value.indexOf(" " + c_name + "="); | |
if (c_start == -1) | |
c_start = c_value.indexOf(c_name + "="); | |
if (c_start == -1) { | |
c_value = null; | |
} else { | |
c_start = c_value.indexOf("=", c_start) + 1; | |
var c_end = c_value.indexOf(";", c_start); | |
if (c_end == -1) | |
c_end = c_value.length; | |
c_value = unescape(c_value.substring(c_start,c_end)); | |
} | |
return c_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment