Develop
2013.04.23 16:25
[js] 파이어폭스(Firefox;F/F)에서 outerHTML 작동하도록 만든 메소드
조회 수 16443 댓글 0
outerHTML 파이어폭스(F/F)에서 쓰는 방법
outerHTML 파이어폭스(F/F)에서 쓰는 방법 <html> <title>outerHTML 파이어폭스 대응</title> <script> /************************************** * 샘플 코드 및 펑션 생성 @ 정민철 * http://tost.tistory.com * * 원본 참조소스 * http://snipplr.com/view/5460/outerhtml-in-firefox/ * http://www.phpschool.com/gnuboard4/bbs/ * board.php?bo_table=tipntech&wr_id=56477 ***************************************/ //ff대응 outerhtml결과 function getouterHtml(obj) { var html = null; //널처리 if (obj == null) return null; if (typeof(obj.outerHTML) == "string") {//스트링값을 가져온다면 IE로 가정함 html = obj.outerHTML; //alert("ie"); //디버그용 } else { html = (new XMLSerializer).serializeToString(obj); //alert("ff"); //디버그용 } return html; } //ff대응 outerhtml 삽입 function setOuterHtml(obj, html) { if (obj == null) return; //null처리 if (typeof(obj.outerHTML) == "string") {//스트링값을 가져온다면 IE로 가정함 //alert("ie"); //디버그용 obj.outerHTML = html; } else { //alert("ff"); //디버그용 var el = document.createElement('divs'); el.innerHTML = html; var range = document.createRange(); range.selectNodeContents(el); var documentFragment = range.extractContents(); obj.parentNode.insertBefore(documentFragment, obj); obj.parentNode.removeChild(obj); } } </script> <body> <divs id="test" style="background:yellow;"> 원래본문 </divs> <script> var divsobj = document.getElementById("test"); </script> <a href="javascript:alert(getouterHtml(divsobj))"> outer값확인 </a> <a href="javascript:setOuterHtml(divsobj, 'htmltest')"> outer값 변경 </a> </body> <html>
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
709 | Develop | [matlab] 정보은닉 스테가노그래피(Steganography) 수업 | hooni | 2016.10.03 | 682 |
708 | Develop | [matlab] ZigZag-Scanning (2-D Array) | hooni | 2016.10.15 | 1984 |
707 | Develop | [linux] 프로세스 관련 시스템콜 | hooni | 2003.04.23 | 7827 |
706 | Develop | [linux] 임베디드 리눅스 (embedded linux) | hooni | 2013.04.23 | 7354 |
705 | Develop | [linux] 쉘 스크립트를 이용한 BBS | hooni | 2003.04.23 | 10047 |
704 | Develop | [linux] 날짜나 파일의 내용으로 검색하는 방법(find 명령 사용) | hooni | 2013.04.23 | 8114 |
703 | Develop | [linux] tar 명령어 뽀개기.. ㅋㅋ | hooni | 2003.04.23 | 7669 |
702 | Develop | [linux] crond 사용법.. ㅋㅋ | hooni | 2013.04.23 | 7246 |
701 | Develop | [linux] CentOS Apache 웹서버에 HTTPS 적용 | hooni | 2015.10.23 | 786 |
700 | Develop | [lego] 세그웨이 이것만 볼것.. ㅎㅎ | hooni | 2013.04.23 | 33536 |
699 | Develop | [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 | hooni | 2020.12.15 | 819 |
698 | Develop | [js]모바일 웹에서 orientationchange | hooni | 2013.04.23 | 19357 |