문서 주소의 제일 앞에 나오는 콜론(:)까지의 송신 방식을 나타내는 문자열 정보를 반환하거나 설정한다.

Script[sVal=]object.protocol
HTML없음
인수
object : (개체 이름)

연결 개체의 이름이다.

sVal : (속성 문자열)
protocol 속성값은 문서 주소의 제일 앞에 나오는 콜론(:)까지의 송신 방식을 나타내는 문자열이다.

이 속성은 읽기/쓰기이며 디폴트값은 없다.

구문
document.write(location.protocol)
document.links[0].protocol='Val'
protocol의 종류

protocol 속성은 문서의 송신방법을 나타내는 문자열로 문서의 제일 처음 부분으로 콜론(:)까지를 포함하며,
http:, ftp;, mailto:등으로 아래와 같다.

URL typeProtocol예제
Navigator info about: about:cache
File file:/ file:///javascript/methods.html
FTP ftp: ftp://ftp.mine.com/home/mine
Gopher gopher: gopher.myhost.com
World Wide Web http: http://home.netscape.com/
JavaScript code javascript: javascript:history.go(-1)
MailTo mailto: mailto:info@netscape.com
Usenet news: news://news.scruznet.com/comp.lang.javascript
Navigator source viewer view-source: view-source:wysiwyg://0/file:/c|/temp/genhtml.html
특기

protocol 속성은 정보를 호스트에서 사용자에게 어떻게 송신하는가를 정의한다.
httpftp protocol이 가장 많이 사용되고 브라우저는 다른 미리 정의된 프로토콜들을 지원한다.

document, imglocation 개체에서는 protocol 속성이 읽기전용이다.

location.protocol 속성은 주소의 앞쪽 문자열을 첫번째 콜론(:)까지를 포함하여 반환한다.(예: http:).
반면 document.protocol은 프로토콜 약어를 반환한다.(예: Hypertext Transfer Protocol을 http로)

protocol 속성은 언제나 설정이 가능하지만, href 속성으로 연결을 새로 설정하여 사용하는 것이 안전하다.

적용
개체scriptHTML규격IE
a[sVal=]a.protocol없음없음IE3.02(win16,win32,mac),IE4.0(ce,unix)
area[sVal=]area.protocol없음없음IE3.02(win16,win32,mac),IE4.0(ce,unix)
document[sVal=]document.protocol없음없음IE3.02(win16,win32,mac),IE4.0(ce,unix)
img[sVal=]img.protocol없음없음IE4.0(win16,win32,ce,unix,mac)
link[sVal=]link.protocol없음없음 
location[sVal=]location.protocol없음없음IE3.02(win16,win32,mac),IE4.0(ce,unix)


property
protocol 속성
protocol</b> 속성이전페이지로페이지 맨위로페이지 맨아래로

간단한 protocol 속성 예제

trio 게시판
http://trio.co.kr/cgi/bbs/triobbs.cgi?db=triobbs
http:
<A href="http://trio.co.kr/cgi/bbs/triobbs.cgi?db=triobbs">trio 게시판</A><BR>
<SCRIPT>
for (i=0;i<document.links.length;i++){
  if(document.links[i].hostname=='trio.co.kr')
    document.write(document.links[i].href+'<BR><FONT color=blue>'+document.links[i].protocol+'</FONT><BR>');
}
</SCRIPT>

다른 protocol 속성 예제

document.location.protocol=http:
location.protocol=http:
document.protocol=undefined
<SCRIPT>
document.write('document.location.protocol=<FONT color=blue>'+document.location.protocol+'</FONT><BR>');
document.write('location.protocol=<FONT color=blue>'+location.protocol+'</FONT><BR>');
document.write('document.protocol=<FONT color=blue>'+document.protocol+'</FONT><BR>');
</SCRIPT>

현재 페이지의 protocol 속성 모두 보기 예제

결과 표시창
<SCRIPT>
function allProtocol(){
  allLinks=document.links;
  str='allLinks.length='+allLinks.length+'<BR>';
  for (i=0;i<ALLLINKS.length;i++){
    if (!allLinks[i].protocol) return;
    str+='allLinks['+i+'].protocol='+allLinks[i].protocol+'<BR>';
  }
  showA.innerHTML=str;
}
</SCRIPT>
<BUTTON onclick=allProtocol()>페이지의 프로토콜 모두 보기</BUTTON>
<DIV id=showA>결과 표시창</DIV>

property
protocol 속성
견본
이전페이지로페이지 맨위로
최종 수정:
07/09/2025 13:05:40
KoXo Homepage
All right reserved
비정상적인 방식으로 프레임없이 페이지에 접속하면 자주 오류가 발생됩니다.
오류가 나면 정상적 접속으로 시도해 보세요.
http://koxo.com/lang/js/property/protocol.html