|
http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=23528 [복사]
http://www.asdfasdf.com/#hash1=value1&hash2=value2
이런식으로 # 뒤에 있는걸 location.hash 라고 하는데요
그 hash를 set하고 get하는 함수를 만들어봤습니다
현재
http://leaveret.cafe24.com 에 적용해서 사용중입니다
오랜시간동안 계획을 하고 만든게 아닌 2~3시간만에 만든함수라 버그가 존재할수 있습니다
이메일이나 댓글로 피드백해주시면 감사하겠습니다
p.s. 나중에 사이트 제작완료하면 실제적인 피해를 입히지 않는선에서 모의해킹좀 부탁드립니다 ㅜㅜ
/* Set Hash */
function setHash(varName, value, cookiename, cookievalue){
var hashArr = new Array();
var foundHash = 0;
if(parent.location.hash.indexOf(varName+"="+value) != -1)
return 0;
if(parent.location.hash.indexOf(varName) != -1){
hashArr = parent.location.hash.split("&");
for(var i=0;i<hashArr.length;i++){
if(hashArr[i].indexOf(varName) != -1){
hashArr[i] = varName+"="+value;
}
if(hashArr[i].length){
if(i==0)
parent.location.hash=hashArr[i]+"&";
else
parent.location.hash += hashArr[i]+"&";
}
}
hashchangebysetHash=1;
}
}
/* Get Hash */
function getHash(hash_name){
if(!hash_name) return parent.location.hash;
if(!paret.location.hash.length) return null;
var i,x,y,ARRhases=parent.location.hash.split("#")[1];
ARRhashes = ARRhashes.split("&");
for (i=0;i<ARRhashes.length;i++){
x=ARRhashes[i].substr(0,ARRhashes[i].indexOf("="));
y=ARRhashes[i].substr(ARRhashes[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if(x==hash_name){
return unescape(y);
}
}
}
getHash 는 구글검색에서 어떤분이 만들어두신 getCookie함수를 변수만 변형시켰습니다
유용하게 써주세요~ :) |
Hit : 9890 Date : 2012/04/01 06:23
|