사용법

content = StripHTML(content)


Function StripHTML(oSource)


    dim Result_Text

 

    Result_text = ReplaceText(oSource," ( )+"," ")

    Result_text = Replace(Result_text,"=" & vbcrlf,"")
    Result_text = Replace(Result_text,";" & vblrcf,"")

    ' Remove the header (prepare first by clearing attributes)

   ' head 태그 안의 모든 내용을 지운다
    Result_text = ReplaceText(Result_text,"<( )*head([^>])*>","<head>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*head( )*>)","</head>")
    Result_text = ReplaceText(Result_text,"(<head>)[\s\S]*(</head>)","")

    ' remove all scripts (prepare first by clearing attributes)

   ' script 태그 안의 모든 내용을 지운다
    Result_text = ReplaceText(Result_text,"<( )*script([^>])*?>","<script>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*?script()*>)","</script>")
    Result_text = ReplaceText(Result_text,"(<script>)([^(<script>\.</script>)])*?(</script>)","")
    Result_text = ReplaceText(Result_text,"(<script>)[\s\S]*?(</script>)","")

    ' remove all styles (prepare first by clearing attributes)

   ' style 태그 안의 모든 내용을 지운다
    Result_text = ReplaceText(Result_text,"<( )*style([^>])*?>","<style>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*?style( )*>)","</style>")
    Result_text = ReplaceText(Result_text,"(<style>)[\s\S]*?(</style>)","")

    ' remove all object (prepare first by clearing attributes)

   ' object 태그 안의 모든 내용을 지운다
    Result_text = ReplaceText(Result_text,"<( )*object([^>])*?>","<object>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*?object( )*>)","</object>")
    Result_text = ReplaceText(Result_text,"(<object>)[\s\S]*?(</object>)","")

    ' Remove the link (prepare first by clearing attributes)

   ' link 태그 안의 모든 내용을 지운다
    Result_text = ReplaceText(Result_text,"<( )*link([^>])*>","<link>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*link( )*>)","</link>")
    Result_text = ReplaceText(Result_text,"(<link>)[\s\S]*(</link>)","")   

   ' 자바스크립트 함수 치환

    Result_text = ReplaceText(Result_text,"onclick=","xonclick=")   
    Result_text = ReplaceText(Result_text,"onmouseover=","xonmouseover=")   
    Result_text = ReplaceText(Result_text,"onmouseout=","xonmouseout=")   
    Result_text = ReplaceText(Result_text,"onchange=","xonchange=")   
    Result_text = ReplaceText(Result_text,"href=""javascript","href=""xjavascript")   

   ' span 및 div 태그의 속성을 제거

    Result_text = ReplaceText(Result_text,"<( )*span([^>])*?>","<span>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*?span( )*>)","</span>")

    Result_text = ReplaceText(Result_text,"<( )*div([^>])*?>","<div>")
    Result_text = ReplaceText(Result_text,"(<( )*(/)( )*?div( )*>)","</div>")  

 

   ' input 태그를 지운다

    Result_text = ReplaceText(Result_text,"<( )*input([^>])*?>","")
           
    ' Remove remaining tags like <a>, links, images, comments etc - anything thats enclosed inside < >

   ' 허용태그 이외의 태그 제거


    Result_text = ReplaceText(Result_text,"<[^(image|a|div|span|table|tr|td|li|p)]*?>","")
   
    ' Thats it.
    StripHTML = Result_Text
End Function

 

Function ReplaceText(str1, patrn, replStr)
   Dim regEx
   Set regEx = New RegExp
   with regEx
      .Pattern = patrn
      .IgnoreCase = True
      .Global = True
   end with
   ReplaceText = regEx.Replace(str1, replStr)
End Function

 

 

 

출처 : Tong - jupiter0410님의 § Program §통

크리에이티브 커먼즈 라이선스
Creative Commons License

/*◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆*/
/*
Input값 형식
   url  :   연결할 페이지("/OnlineSvc/Prviate/main.aps?action=view")
   Width  :   브라우저의 너비     숫자만 입력하세요(500=>○, '500'=>X,"500"=>X)
   Height  :   브라우저의 높이     숫자만 입력하세요(500=>○, '500'=>X,"500"=>X)
   Center  :   브라우저의 가운데 여부   true or false
   Toolbar  :   브라우저의 툴바 표시여부  yes or no
   Resizable :   브라우저의 사이즈 조정 가능여부 yes or no
   Scrollbars :   브라우저의 스크롤바 표시여부 yes or no
   Left  :   브라우저의 왼쪽 위치   숫자만 입력하세요(10=>○, '10'=>X,"10"=>X)
   Top   :   브라우저의 윗쪽 위치   숫자만 입력하세요(10=>○, '10'=>X,"10"=>X)
*/


//openWin:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바 없는 창입니다.)
function openWin(url,Width,Height,Center) {
   if (Center==true){
      window.open(url, "", "toolbar=no,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
   }
   else {
      window.open(url, "", "toolbar=no,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=0,top=0");
   }
}


//openWin_All:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바 포함하는 창입니다.)
function openWin_All(url,Width,Height,Center) {
   if (Center==true){
      window.open(url, "", "toolbar=yes,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
 }
   else {
  window.open(url, "", "toolbar=yes,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=0,top=0");
   }
}


//openWin_Toolbar:PopUp창을 띄우는 함수로 툴바만 창입니다.)
function openWin_Toolbar(url,Width,Height,Center) {
   if (Center==true){
      window.open(url, "", "toolbar=yes,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
   }
   else {
      window.open(url, "", "toolbar=yes,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=0,top=0");
   }
}


//openWin_Resizable:PopUp창을 띄우는 함수로 사이즈를 변경가능한 창입니다.)
function openWin_Resizable(url,Width,Height,Center) {
   if (Center==true){
      window.open(url, "", "toolbar=no,resizable=yes,scrollbars=no,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
   }
   else {
      window.open(url, "", "toolbar=no,resizable=yes,scrollbars=no,width=" + Width + ",height=" + Height + ",left=0,top=0");
   }
}


//openWin_Scrollbars:PopUp창을 띄우는 함수로 스크롤바가 있는 창입니다.)
function openWin_Scrollbars(url,Width,Height,Center) {
   if (Center==true){
      window.open(url, "", "toolbar=no,resizable=no,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
   }
   else {
      window.open(url, "", "toolbar=no,resizable=no,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=0,top=0");
   }
}


//openWin_Scrollbars:PopUp창을 띄우는 함수로 스크롤바가 있는 창입니다.)
function openWin_R_S(url,Width,Height,Center) {
   if (Center==true){
      window.open(url, "", "toolbar=no,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
 }
   else {
      window.open(url, "", "toolbar=no,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=0,top=0");
   }
}


//openWin_Scrollbars:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바등을 모든 값을 정의하는 창입니다.)
function openWin_definition(url,Center,Toolbar,Resizable,Scrollbars,Width,Height,Left,Top) {
    window.open(url, "", "toolbar=" + Toolbar+ ",resizable=" + Resizable + ",scrollbars=" + Scrollbars + ",width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top);
}
//-->

크리에이티브 커먼즈 라이선스
Creative Commons License

input박스가 한개인 폼에서는 엔터를 치면 스크립트가 실행안되고 그냥 엑션으로 submit된다

이를 막기위해 폼엑션에 스크립트를 넣는다

<form action="javascript:search();" method="post" ...

토들러몰의 검색input박스의 예다

이러면 엔터를 처도 검색버튼을 눌러도 내용을 넣으라는 스크립드가(search()) 실행된다

 
크리에이티브 커먼즈 라이선스
Creative Commons License

해당 값을 encodeURIComponent(value) 로 해서 넘겨주면 됩니다. 받는측에서 UTF-8로 처리되어 있으면 해당값을 UTF-8로 받을 수 있습니다.

ex) location.href="aaa.asp?serial="+encodeURIComponent(nSerial)

크리에이티브 커먼즈 라이선스
Creative Commons License

function showplatformrow()
{
    if (SearchForm.ItemType.selectedIndex == 1)
    { document.getElementById('ProductRow').style.display = 'block'; }
    else
    {
    SearchForm.Platform.selectedIndex = 0;
    document.getElementById('ProductRow').style.display = 'none';
    }
}


일반적으로 위의 코드처럼 style.display='block' 하고 style.display='none'를 많이들 사용한다.

그러나 <tr> 부분을 지정해두고 block , none을 반복해보면 파이어폭스에서는 이상한 일이 발생하는것을 살펴볼 수가 있다.

여기에서 문제는 block 부분이다. style.display='block'을 style.display='' 이렇게 변경하면 IE와 파이어폭스에서 모두 정상적으로 동작하는것을 볼수있다.

크리에이티브 커먼즈 라이선스
Creative Commons License

알 수 없는 런타임 오류가 발생할 수 있는 가능성은 무지하게 많지만, IE에서는 발생하고 FireFox에서는 발생하지 않는다면 읽기전용 속성 태그에 ID를 부여하고 innerHTML을 사용했을 가능성이 있다.

** IE에서 COL COLGROUP FRAMESET HTML STYLE TABLE TBODY TFOOT THEAD TITLE TR 개체에서는 읽기전용이고 그 외의 개체에서는 모두 읽기/쓰기이다. 디폴트값은 없다.
크리에이티브 커먼즈 라이선스
Creative Commons License

IE에서는 style="cursor:hand;" 라고 하면 정상적으로 동작을 하게 된다. 하지만 이는 IE에서 만든 변종코드로, 파이어폭스(firefox)등의 다른 브라우저에서는 정상적인 동작을 하지 않는다.

타 브라우저에서는 cursor:point 라는 표준을 지키고 있다.

따라서 IE와 파이어폭스등의 타브라우저까지 동시에 정상적으로 동작하게 하기 위해서는

style="cursor:pointer;cursor:hand;" 이라고 변경해 주어야 하며, 주의할 점은 cursor:pointer가 먼저 나와야 한다는것!
크리에이티브 커먼즈 라이선스
Creative Commons License

onkeydown="event.returnValue=false;" 를 추가해주면 됩니다.

[CODE type=html]<input name="file" type="file" size="60" id="file" onkeydown="event.returnValue=false;">[/CODE]

이렇게 해주면 직접 타이핑 치는것을 방지할 수 있습니다.



크리에이티브 커먼즈 라이선스
Creative Commons License