Skip to content

Instantly share code, notes, and snippets.

@riix
Last active November 1, 2021 05:40
Show Gist options
  • Select an option

  • Save riix/4386075 to your computer and use it in GitHub Desktop.

Select an option

Save riix/4386075 to your computer and use it in GitHub Desktop.
activeX.js
/****************************************************
* @version : 1.6
* @date :
* @author : 박한얼
* @organization : Daum Communications UI Dev.
----------------------------------------------------------------
- id와 name이 없을 경우는 daumActiveXObject[0~99]로 임의로 생성
- id와 name중 하나만 값을 넣을 경우, id와 name을 같은 값으로 설정
- id와 name의 값을 모두 지정한 경우, 해당값으로 설정
- width와 height를 지정하지 않은 경우는 100%를 기본값으로 설정
- codebase를 지정하지 않은 경우는 empty string으로 설정
- activeX에 필요한 파라미터는 한쌍의 배열로 name과 value를 지정
ex)
----------------------------------------------------------------
<div id="activeXControl"></div>
<script type="text/javascript" src="activeX.js"></script>
<script type="text/javascript">
<!--
var obj = new Object();
obj.classid = 'CLSID:A00B2A53-60D9-4477-ADA3-60490770C5E0';
obj.id = 'FileUpload';
obj.name = 'FileUpload';
obj.width = '100%';
obj.height = '126';
obj.codebase = '/hanmail-ax/hanmail.cab#version=1,0,0,21';
var param = [
['PID','30476'],
['ActionTime','20060123161002'],
['BIG_UploadURL','/Mail-bin/bigfile_attach.cgi'],
['BIG_PrecheckURL','/Mail-bin/bigfile_precheck.cgi'],
['BIG_ServerName','bigmail21.mail.daum.net'],
['MaxNormalSize','200480000'],
['MinBigFileSize','20480000'],
['MaxFileCount','10'],
['BIG_ExpireDay','7'],
['Normal_ServerName','premium65.daum.net'],
['Normal_UploadURL','/Mail-bin/attach_mail.frame_ax.cgi'],
];
obj.param = param;
daumActiveX(obj,'activeXControl');
// -->
</script>
----------------------------------------------------------------
* version history
- 1.0
; object, embed 태그를 js로 삽입
; ie의 경우 object 태그로, 이외의 경우 embed 태그로 activex 삽입
- 1.1
; 모질라의 경우 swf에 파라미터를 전달할 경우 flashvars를 src.swf?var=aaa로 값 전달 할 수 있도록 변경.
- 1.2
; IE에서 오랜시간 동안 '페이지 로딩 중...'으로 표시되는 문제 해결
; 모질라에서 wmode=transparent 안되던 문제 해결
- 1.3
; MS에서 제시한 구현방법대로 했을 경우 이미 설치된 ActiveX의 경우에는 문제가 없으나,
아직 설치되지 않은 ActiveX의 경우 '설치하시겠습니까?'라는 창이 뜨지 않고, x-box로 표시되는 문제 해결.
- 1.4
; onerror, onmouseover 등의 이벤트 핸들링에 대한 코드 추가.
- 1.5
; ie외의 브라우저에서 Flash 및 Windows Media Player 표시가능하도록 변경. (windows 환경에서만 wmp 가능)
----------------------------------------------------------------
* 새로운 버젼 적용 방법
- daumActiveX 함수만 최근 버젼으로 교체.
*/
function daumActiveX(obj,div){
// generate html code
// for ie obejct
var html = '<object ';
if (!obj.id && !obj.name){
var r = Math.round(Math.random()*100);
html += 'id="daumActiveXObject'+r+'" name="daumActiveXObject'+r+'" ';
} else {
if (obj.id) html += 'id="'+obj.id+'" ';
else html += 'id="'+obj.name+'" ';
if (obj.name) html += 'name="'+obj.name+'" ';
else html += 'name="'+obj.id+'" ';
}
if (obj.type) html += 'type="'+obj.type+'" ';
if (obj.classid) html += 'classid="'+obj.classid+'" ';
if (obj.width) html += 'width="'+obj.width+'" ';
if (obj.height) html += 'height="'+obj.height+'" ';
if (obj.codebase) html += 'codebase="'+obj.codebase+'" ';
// append events
for (var i in obj.events){
if (obj.events[i]){
html += obj.events[i][0]+'="'+obj.events[i][1]+'" ';
}
}
// end of object tag
html += '>\n';
// append params
for (var i in obj.param){
html += '<param name="'+obj.param[i][0]+'" value="'+obj.param[i][1]+'"/>\n';
}
// for ns embed
html += '<embed ';
if (!obj.id && !obj.name){
var r = Math.round(Math.random()*100);
html += 'id="daumActiveXObject'+r+'" name="daumActiveXObject'+r+'" ';
} else {
if (obj.id) html += 'id="'+obj.id+'" ';
if (obj.name) html += 'name="'+obj.name+'" ';
}
if (obj.type) html += 'type="'+obj.type+'" ';
if (obj.width) html += 'width="'+obj.width+'" ';
if (obj.height) html += 'height="'+obj.height+'" ';
// append params
for (var i in obj.param){
if (obj.param[i][0]){
if (obj.param[i][0]=='movie' || obj.param[i][0]=='src'){
var _src = obj.param[i][1];
}
if (obj.param[i][0].toLowerCase()=='flashvars'){
if (_src){
var tmpArr = html.split('src="'+_src+'"');
html = tmpArr[0]+' src="'+_src+'?'+obj.param[i][1]+'" '+tmpArr[1];
} else {
obj.param[obj.param.length] = obj.param[i];
}
} else {
html += obj.param[i][0]+'="'+obj.param[i][1]+'" ';
}
}
}
html += '/>\n';
html += '</object>';
var isIE = (document.all)?true:false;
if (isIE){
document.getElementById(div).innerHTML = html;
} else if (obj.type=='application/x-shockwave-flash' || obj.classid.toLowerCase()=='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'){
// ie외의 브라우저에서 activex가 flash 경우만 노출
document.getElementById(div).innerHTML = html;
} else if (navigator.platform.indexOf('Win')>=0 && obj.classid.toLowerCase()=='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95'){
// Windows Media Player의 경우 windows platform에서만 노출
document.getElementById(div).innerHTML = html;
}
}
// 한페이지에 한종류의 activeX가 복수개 삽입되는 경우 하단과 같이 function을 만들어서 사용
function daumFlash(src,width,height,div, vars){
var obj = new Object();
obj.type = 'application/x-shockwave-flash';
obj.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
obj.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
obj.wmode = 'transparent';
obj.width = width;
obj.height = height;
var param = [
['movie',src],
['src',src],
['quality','high'],
['wmode','transparent'],
['bgcolor','#FFFFFF'],
['pluginspage','http://www.macromedia.com/go/getflashplayer'],
['allowScriptAccess','Always'],
];
if(vars){
param[param.length] = ['FlashVars',vars];
}
obj.param = param;
daumActiveX(obj,div);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment