안녕하세요. 브라우저 용 writting 플러그인이 새로 생겼습니다. 내 요구 사항은 URL의 쿠키 값을 읽으려면 샘플 javascript 플러그인 코드를 작성해야하며 모든 브라우저를 지원해야한다는 것입니다. 방금 시스템의 쿠키 파일에서 직접 읽을 수 없으며 Chrome 용 sqlite 데이터베이스를 통해 처리해야한다는 것을 알았습니다. 진행 방법이 도움이 될 것입니다.브라우저에서 URL의 쿠키 값을 읽는 Javascript 플러그인
-1
A
답변
0
이 코드를 사용하십시오.
$.cookie('the_cookie', 'the_value');
//Create expiring cookie, 7 days from then:
$.cookie('the_cookie', 'the_value', { expires: 7 });
//Create expiring cookie, valid across entire page:
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
//Read cookie
$.cookie('the_cookie'); // => 'the_value'
$.cookie('not_existing'); // => null
//Delete cookie by passing null as value:
$.cookie('the_cookie', null);
// Creating cookie with all availabl options
$.cookie('myCookie2', 'myValue2', { expires: 7, path: '/', domain: 'example.com',
secure: true, raw: true });
및 https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js
+0
jQuery 태그가 보이지 않는다. – mishik
+0
jquery가 아닌 javascript를 사용하여 개발해야한다. –
0
쿠키 문자열 형식으로
몇 가지 예 document.cookie를 통해 액세스 할 수있는이 URL에서 다운로드 JQuery와 쿠키() : 당신이 그것을 읽어 갔다
document.cookie = "YOUR_KEY_1=YOUR_VALUE_1;YOUR_KEY_2=YOUR_VALUE_2;..."
그리고 쿠키를 설정할 때 (쿠키로 쿠키)
console.log(document.cookie)
/* "YOUR_KEY=YOUR_VALUE; expires=EXPIRATION_DATE; path=WHERE_YOUR_COOKIE_WILL_BE_ACCESSIBLE"
eg.
user=599a9182df1...; expires=Tue, 15 Jul 2014 14:06:12 GMT; path=/logged_in
So, the cookie "user" as the value 599a9182df1... (Some SHA1 example)
It expires in 1 year (Won't be accessible if not renewed)
Is only accessible under /logged_in
*/
두 가지 기능 (가져 오기 및 설정)과 사용 방법 예를 만들었습니다.
// Definition of the cookie duration
var my_cookie_duration_hash = {
days: 1,
hours: 0,
minutes: 0,
seconds: 0
};
// Definition of the cookies key/value pair
var my_cookies = {
key1: 'value1=',
key2: 'value2'
};
// Let's set some cookies
set_cookies(my_cookies, my_cookie_duration_hash, '/');
// Let's get our cookies
window.alert(get_cookies()['key1']);
/*****************************************************************
Cookie home made functions
*****************************************************************/
// Get the cookie key/value in JSON format
function get_cookies() {
var cookies = {};
cookies_str = document.cookie.split(';');
// Processing the cookies
for(var i = 0 ; i < cookies_str.length ; i++) {
cookie = cookies_str[i];
var cookie_match = cookie.match(/^([^=]*)=(.*)$/);
// If The cookie exist, we get it back in a JSON
if(cookie_match) {
cookies[cookie_match[1]] = cookie_match[2];
}
}
// We return the cookies in a JSON format
return cookies;
}
// Set the cookies
// arg(0) : Cookies values
// Format : Some { key: value } JSON object
// arg(1) : Cookie duration
function set_cookies() {
cookies = arguments[0] || {};
cookie_duration = arguments[1] || {};
cookie_domain = arguments[2] || '/';
if(typeof(cookie_duration) === 'object') {
my_cookie_duration_int = (cookie_duration.days || 0) * 24 * 60 * 60 * 1000;
+ (cookie_duration.hours || 0) * 60 * 60 * 1000;
+ (cookie_duration.minutes || 0) * 60 * 1000;
+ (cookie_duration.seconds || 0) * 1000;
} else if(typeof(cookie_duration) === 'number') {
my_cookie_duration_int = cookie_duration;
} else if(typeof(cookie_duration) === 'undefined') {
my_cookie_duration_int = 0;
} else if(typeof(cookie_duration) !== 'undefined') {
console.error(typeof(cookie_duration) +' is not a recognize type for the cookie duration.');
}
// Calculation of the cookie end of validity
var date = new Date();
var end_date = date.getTime() + my_cookie_duration_int;
date.setTime (end_date);
var my_cookie_expiration_date = date.toGMTString();
// Processing of the cookie
for(var my_cookie in cookies) {
new_cookie = my_cookie +"="+ cookies[my_cookie]
+ "; expires="+ my_cookie_expiration_date
+ "; path="+ cookie_domain;
// Definition of the cookies
document.cookie = new_cookie;
}
}
나는 그것이 도움이되기를 바랍니다 (IE6 & 파이어 폭스 (22)와 호환).
관련 문제
- 1. 쿠키 값을 읽는 동안 쿠키 값이 잘못되었습니다.
- 2. Java를 사용하여 쿠키 값을 설정하고 읽는 방법
- 3. 안드로이드 MediaPlayer를 URL의 쿠키
- 4. cakephp보기 파일에서 쿠키 값을 읽는 방법
- 5. jQuery 쿠키 플러그인을 사용하여 쿠키 값을 설정/읽는 방법
- 6. jQuery 쿠키 플러그인 - 쿠키 확인
- 7. JQuery와 쿠키 플러그인
- 8. URL의 javascript/VBScript를 차단하고 있습니다.
- 9. Javascript/Jquery의 영구 쿠키
- 10. 백본 + 브라우저에서 jquery 플러그인
- 11. jQuery를 쿠키 플러그인
- 12. 브라우저에서 쿠키 이동
- 13. Java에서 쿠키 삭제/브라우저에서 쿠키 삭제 방법
- 14. asp 쿠키 대 javascript 쿠키
- 15. 어떻게 javascript 쿠키 업데이트
- 16. jQuery 쿠키 플러그인 JSON 객체 읽기
- 17. 게시 값을 저장할 쿠키
- 18. jquery 쿠키 플러그인 사용
- 19. jQuery 쿠키 플러그인 구현
- 20. jquery 쿠키 플러그인 문제
- 21. 브라우저에서 HTTP 쿠키 가져 오기
- 22. 브라우저에서 REST URL의 액세스를 제한하십시오.
- 23. 브라우저에서 파일을 저장하는 Javascript?
- 24. jquery 쿠키 플러그인 또는 PHP 쿠키?
- 25. 쿠키 이해 (jquery 쿠키 플러그인 사용)
- 26. javascript/jQuery를 사용하여 쿠키 제거
- 27. URL의 사회적 신호를 읽는 방법
- 28. jQuery 쿠키 플러그인 문제 (쿠키 만료가 작동하지 않음)
- 29. 쿠키 값을 삭제하는 방법
- 30. 닫힌 브라우저에서 PHP 쿠키 유지하기
무엇을 이미 시도 했습니까? – mishik
@mishik : w3 schools.Below의 샘플 코드를 사용해 보았습니다. 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)); } 경고 (c_value) return c_value; } 그러나 이것이 어떻게 도움이 될지 잘 모르겠다. –