hash 에 관련해서 뭔가를 끄집어내려고 검색을 해보다가
몇가지... 키워드를 발견해서 검색해봤지만,
jQuery 와 관련된 내용들이 너무 많아서
키워드 몇개 ( hash, onpropertychange, attachEvent )를 건진 후
... 내가 해석하기 좋은 형식으로 샘플을 만들기 시작했다.
...
<html><head><title>hashReceiver</title></head>
<body>
<script>
// init Consol
var consolID='Consol_1', consolCount=0;
document.write('<div id='+consolID+'></div>');
// end of init Consol
// sendtoConsolFunction
function sendtoConsol() {
var ar=arguments, i, e=document.getElementById(consolID), ov='';
for (i=0; i<ar.length; i++) ov+=ar[i];
e.innerHTML+='-'+ov+'-<br/>';
consolCount++;
}
</script>
<script>
function hashAlerter() {
sendtoConsol(location.hash);
}
function inithashAlerter() {
// hash receiver Initialize
// only IE 7 ? or less?
if (document.all&&('attachEvent' in document)) document.attachEvent('onpropertychange', hashAlerter);
// document.all - check IE... skip for Opera (opera have attachEvent = =;...)
// no IE, less version
else window.onhashchange=hashAlerter;
}
inithashAlerter();
</script>
</body></html>
...
inithashAlerter() 에 if 문이 왜 많으냐하면(?),
attachEvent 가 Opera 에도 있기 때문. (= =;... Opera 에서 onpropertychange 넣어도 작동이 안되던데...)
IE 외에는 onhashchange 라는 property가 존재하기때문에 저렇게 초기화를 시켜놨다.
물론, consol 은 급하게 consol 출력화면을 표시하기 위해 만든 bonus...
...
그런데... = =;... hash 테스트는 직접 # 을 입력하거나,...해서 test 해야하잖아...
그래서... 임시로나마 이렇게 테스터기(?)를 또 만들어야했다.
...
<iframe width=400 height=200 name=iframe101215_1></iframe><br/>
<div onclick=if(document.frames)document.frames['iframe101215_1'].focus(); >
<a href=http://cfs.tistory.com/custom/blog/42/429787/skin/images/hashConsol.html#1 target=iframe101215_1>v1#1</a>
<a href=http://cfs.tistory.com/custom/blog/42/429787/skin/images/hashConsol.html?1 target=iframe101215_1>v1?1</a>
<a href=http://cfs.tistory.com/custom/blog/42/429787/skin/images/hashConsol.html?1#1 target=iframe101215_1>v1?1#1</a>
<a href=http://cfs.tistory.com/custom/blog/42/429787/skin/images/hashConsol.html?1#2 target=iframe101215_1>v1?1#2</a>
</div>
...
...
이것도 만들면서 또 고생한게,
IE 에서만 onpropertychange 를 적용한 문제에 이어서(응?)
focus 가 해당 iframe 에 가지 않으면 onpropertychange 도 작동이 안됐다.
물론, hashConsol.html 내에 해당 hash name 을 가진 elementId 가 존재한다면 작동을 했겠지만,
= =;... 지금 저 내용처럼... 없는 elementId 를 막(?) 적용시켜서 테스트하기때문에...
focus 가 해당 iframe 으로 넘어가지 않았다.
그래서, document.frames 를 이용해서 적용을 시켜놨더니(응?)
= =;.... 다른 웹브라우져에서 document.frames[] 를 지원하지 않는다길래... 급하게 필터링.
...
그렇게 로컬테스트 후 블로그에 올려놨더니...
OTL... IE8 에서 작동을 안하네.... 일일이 포커스 넘기자고 해...도 작동을 안하고...
...
이래저래 미완성본이라도 올려놓고 보니...
-.-... 쓸만할 것 같기는 한데...
테스트결과(?)는
1) IE - onpropertychange 를 이용했기때문에 (응?) 클릭하면
local 테스트시에만 무조건 화면에 표시. (웹에 올리면 한번만 반응 OTL...)
2) FF, Safari, Chrome - onhashchange 가 잘(?) 먹혔다.
단지(?) 두번 이상 같은 내용으로 클릭한 경우, hash 의 변동이 없기 때문에 무시(?)...
3) Opera - onhashchange 가 적용된 것 같은데, 클릭하면 무조건 값을 표시한다. (물론, 처음에는 onhashchange 가 아니니 반응이 없지만...) -.-... 무섭네...
...
결론을 내자면,
1) 중복된 클릭의 경우, 이 함수를 조금 손보면(= =;...) 가능하고...
( var lasthash=location.hash; ... () { if (location.hash==lasthash) return; ... } 형식을 이용해서...)
2) hash 의 클릭을 매번 적용하려 한다면, 조금 더 연구를 해야하고, (= =;...)
3) IE8 의 focus 에 대한 정책(?)문제를 어떻게 해결해야할지... = =;...
뭐... 이정도.
...
NowMark killofki@.
'event' 카테고리의 다른 글
hash] hashConsoll 구현 3... (scroll 부분 패치 & 버그수정) (0) | 2011.01.09 |
---|---|
hash] hashConsol 구현 2... (IE 부분완성) (0) | 2011.01.04 |
hash] hashConsol 구현... (IE 부분완성) (0) | 2010.12.21 |
page 기준의 mouse position 추적... (0) | 2009.09.11 |
mouse position... (0) | 2009.09.09 |