0
쿠키 값을 표시하는 스크립트가 있는데 document.write를 던집니다.div를 30 초마다 새로 고치는 방법은 무엇입니까?
30 초마다 스크립트를 새로 고침 할 수 있습니까?
또는 불가능할 경우 다시 쿠키 값을 가져 오십시오. 값 = GetCookie ('VisitorName');
또는 iframe에 넣고 iframe scr을 다시로드하십시오.
코드는 다음과 같습니다 :
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function Who(info) {
var VisitorName = GetCookie('VisitorName')
if (VisitorName == null) {
VisitorName = "Dear visitor";
SetCookie ('VisitorName', VisitorName, exp);
}
return VisitorName;
}
function set() {
VisitorName = prompt("");
SetCookie ('VisitorName', VisitorName, exp);
}
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc>2) ? argv[2] : null;
var path = (argc >3) ? argv[3] : null;
var domain = (argc >4) ? argv[4] : null;
var secure = (argc >5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : (";expires=" + expires.toGMTString())) +
((path == null) ? "" : (";path=" + path)) +
((domain == null) ? "" : (";domain=" + domain)) +
((secure == true) ? ";secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
document.write("" + Who() + ",")
그것은 다시로드 만 보여주는 결과입니다. 그리고 오래된 값 옆에 새로운 값을 추가합니다. 그래서 각 시간 간격마다 하나의 값 값 값을가집니다! 콘텐츠 페이지에 머물러 이전 값을 삭제하고 싶습니다. 어쩌면 이것을 태그에 삽입해야합니까? – user3381580
프레임이 거의 이동하지 않습니다. 페이지에 div 요소를 작성하고 함수에 쓰기를 원할 것입니다. 꽤 쉽지만 전체 html 코드가 없으면 기술 수준을 알지 못해도 빨리 설명하기가 어렵습니다. 여기에 [허용 된 대답은] (http://stackoverflow.com/questions/15119856/alternative-way-to-use-javascript-to-write-to-a-div-element)를 작성하는 방법을보십시오. div. 이것은'document.write (""+ Who() + ",")'행을 대체합니다. –
내가 다시 같은 결과를 쓴 – user3381580