Tarun Chawla
04/21/2021, 1:29 PMfun setCookie(name: String, value: String, path: String = "/") {
document.cookie = "$name=$value;path=$path"
}
Below api to get cookie:
fun getCookieValue(name: String): String? {
val currentCookies = document.cookie.split(";")
for (cookiePair in currentCookies) {
val cookieKeyValue = cookiePair.split("=")
if (cookieKeyValue.first().trim() == name.trim()) {
return cookieKeyValue[1].trim()
}
}
return null
}
Two questions:
1. Is there any better way to do it?
2. How to delete a cookie key value?Tarun Chawla
04/21/2021, 3:55 PM