'JavaScript'에 해당되는 글 5건
- 2010/05/15 초록별사랑 스크린리더 사용자를 위한 폼 검증 예제
- 2007/07/10 초록별사랑 파일로 부터 xml정보를 가져오는 함수..
- 2007/07/04 초록별사랑 base64 인코더 디코더
- 2007/06/21 초록별사랑 html태그를 없애는 asp 함수
- 2007/01/29 초록별사랑 스패머로부터 이메일주소 보호하는 script
function loadXML(link_url) {
// code for IE
if (window.ActiveXObject) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(link_url);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load(link_url);
}
else {
alert('Your browser cannot handle this script');
}
}
읽혀진 XML로부터
for ( int i = 0 ; i < xmlDoc.getElementsByTagName("url").length ; i++){
xmlDoc.getElementsByTagName("url")[i].childNodes[0].nodeValue
}
위와 같이 값을 가져온다.
ASP 소스
-------------------------------------------------------------------------------
Dim Base64Chars
Base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"abcdefghijklmnopqrstuvwxyz" & _
"0123456789" & _
"+/"
' Functions for encoding string to Base64
Public Function base64_encode( byVal strIn )
Dim c1, c2, c3, w1, w2, w3, w4, n, strOut
For n = 1 To Len( strIn ) Step 3
c1 = Asc( Mid( strIn, n, 1 ) )
c2 = Asc( Mid( strIn, n + 1, 1 ) + Chr(0) )
c3 = Asc( Mid( strIn, n + 2, 1 ) + Chr(0) )
w1 = Int( c1 / 4 ) : w2 = ( c1 And 3 ) * 16 + Int( c2 / 16 )
If Len( strIn ) >= n + 1 Then
w3 = ( c2 And 15 ) * 4 + Int( c3 / 64 )
Else
w3 = -1
End If
If Len( strIn ) >= n + 2 Then
w4 = c3 And 63
Else
w4 = -1
End If
strOut = strOut + mimeencode( w1 ) + mimeencode( w2 ) + _
mimeencode( w3 ) + mimeencode( w4 )
Next
base64_encode = strOut
End Function
Private Function mimeencode( byVal intIn )
If intIn >= 0 Then
mimeencode = Mid( Base64Chars, intIn + 1, 1 )
Else
mimeencode = ""
End If
End Function
' Function to decode string from Base64
Public Function base64_decode( byVal strIn )
Dim w1, w2, w3, w4, n, strOut
For n = 1 To Len( strIn ) Step 4
w1 = mimedecode( Mid( strIn, n, 1 ) )
w2 = mimedecode( Mid( strIn, n + 1, 1 ) )
w3 = mimedecode( Mid( strIn, n + 2, 1 ) )
w4 = mimedecode( Mid( strIn, n + 3, 1 ) )
If w2 >= 0 Then _
strOut = strOut + _
Chr( ( ( w1 * 4 + Int( w2 / 16 ) ) And 255 ) )
If w3 >= 0 Then _
strOut = strOut + _
Chr( ( ( w2 * 16 + Int( w3 / 4 ) ) And 255 ) )
If w4 >= 0 Then _
strOut = strOut + _
Chr( ( ( w3 * 64 + w4 ) And 255 ) )
Next
base64_decode = strOut
End Function
Private Function mimedecode( byVal strIn )
If Len( strIn ) = 0 Then
mimedecode = -1 : Exit Function
Else
mimedecode = InStr( Base64Chars, strIn ) - 1
End If
End Function
java 소스
-----------------------------------------------------------------------------------
public static String base64Encode(String str) {
String result = "";
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
byte[] b1 = str.getBytes();
result = encoder.encode(b1);
return result;
}
public static String base64Decode(String str) {
String result = "";
try {
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
byte[] b1 = decoder.decodeBuffer(str);
result = new String(b1);
} catch (IOException ex) {
}
return result;
}
javascript 소스
-----------------------------------------------------------------------------------
var base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split("");
var base64inv = {}; for (var i = 0; i < base64chars.length; i++) { base64inv[base64chars[i]] = i; }
function base64_encode (s)
{
// the result/encrypted string, the padding string, and the pad count
var r = ""; var p = ""; var c = s.length % 3;
// add a right zero pad to make this string a multiple of 3 characters
if (c > 0) { for (; c < 3; c++) { p += '='; s += "\0"; } }
// increment over the length of the string, three characters at a time
for (c = 0; c < s.length; c += 3) {
// we add newlines after every 76 output characters, according to the MIME specs
if (c > 0 && (c / 3 * 4) % 76 == 0) { r += "\r\n"; }
// these three 8-bit (ASCII) characters become one 24-bit number
var n = (s.charCodeAt(c) << 16) + (s.charCodeAt(c+1) << 8) + s.charCodeAt(c+2);
// this 24-bit number gets separated into four 6-bit numbers
n = [(n >>> 18) & 63, (n >>> 12) & 63, (n >>> 6) & 63, n & 63];
// those four 6-bit numbers are used as indices into the base64 character list
r += base64chars[n[0]] + base64chars[n[1]] + base64chars[n[2]] + base64chars[n[3]];
// add the actual padding string, after removing the zero pad
} return r.substr(0, r.length - p.length) + p;
}
function base64_decode (s)
{
// replace any incoming padding with a zero pad (the 'A' character is zero)
var p = (s.charAt(s.length-1) == '=' ? (s.charAt(s.length-2) == '='
? 'AA' : 'A') : ""); var r = ""; s = s.substr(0, s.length - p.length) + p;
// remove/ignore any characters not in the base64 characters list -- particularly newlines
s = s.replace(new RegExp('[^'+base64chars.join("")+']', 'g'), "");
// increment over the length of this encrypted string, four characters at a time
for (var c = 0; c < s.length; c += 4) {
// each of these four characters represents a 6-bit index in the base64 characters list
// which, when concatenated, will give the 24-bit number for the original 3 characters
var n = (base64inv[s.charAt(c)] << 18) + base64inv[s.charAt(c+3)] +
(base64inv[s.charAt(c+1)] << 12) + (base64inv[s.charAt(c+2)] << 6);
// split the 24-bit number into the original three 8-bit (ASCII) characters
r += String.fromCharCode((n >>> 16) & 255, (n >>> 8) & 255, n & 255);
// remove any zero pad that was added to make this a multiple of 24 bits
} return r.substr(0, r.length - p.length);
}
asp에서 html태그를 없애는 함수가 필요할 때가 있다.
아래 함수를 사용하여 태그를 없앤다.
asp ---------------------------------------------------------------------------
Function stripTag(byval strHTML)
IF Not isNull(strHtml) then
Dim objRegExp, strOutput, strReWord
Set objRegExp = New Regexp '정규식을 만든다.
strReWord = "" '대체문자열
objRegExp.Global = True '전체 문자열검색
objRegExp.Pattern = "<[/]*(!|a|abbr|acronym|address|applet|area|b|base|basefont|bdo|big|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|div|dl|dt|em|fieldset|font|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|hr|html|i|iframe|img|input|ins|isindex|kbd|label|legend|li|link|map|menu|meta|noframes|noscript|object|ol|option|p|param|pre|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|u|ul|var|\?xml|o:)[^>]*>" '전체 패턴정의
objRegExp.IgnoreCase = True '대/소문자 구분하지 않는다.
strOutput = objRegExp.Replace(strHTML,strReWord)
Set objRegExp = Nothing
End IF
stripTag = strOutput
End Function
striptag를 확장시킨다.
Function stripTags(byval strHTML)
stripTags = stripTag(strHTML)
End Function
Javascript-------------------------------------------------------------------
stripTags(str) {
return str.replace(/<\/?[^>]+>/gi, '');
}
name과 domain은 각자의 이메일로 변경하는 센스..
<script language="JavaScript"><!--
var name = "protected";
var domain = "cdrsoft.com";
document.write('<a href=\"mailto:' + name + '@' + domain + '\">');
document.write(name + '@' + domain + '</a>');
// --></script>
웹 메일 서버를 운영하고 싶어서 스팸때문에 운영할 수 없다.
스팸없는 인터넷.. 바로 우리가 원하는 인터넷이 아닐까 한다.
하지만 가끔 스팸에서 좋은 정보를 얻는 경우도 있다. (극히 드물다)
출처 : http://www.javascriptkit.com/script/script2/unspam.shtml

글
댓글을 달아 주세요
댓글 RSS 주소 : http://haroc.haroc.net/tc/rss/comment/473