openFlashWin()
フラッシュをサブウインドウで開くための関数です。引数のターゲット名はwindow.openのターゲット名と同じで同じ名前を指定すればフラッシュは同じウインドウへ読み込まれます。
内幅と内高は開くサブウインドウの内寸でピクセル指定します(100×100以下は指定できません)。X座標,Y座標は、指定しなければスクリーン中央に開きます。
new で得られたwinoj名は普通のサブウインドウと同様にmoveTo(),resizeBy()などで操作できます。Operaはシングルウインドウモードの場合です(マルチウインドウモードの場合はブラウザ内の位置になります)。
*このファンクションをコピーして<script>と</script>の間にペーストしておくだけでこの機能をクロスブラウザに利用できるようになります。
Cross-Browser のための Sample Function
Syntax : winoj = new openFlashWin('フラッシュURL','ターゲット名',内幅,内高[,X座標,Y座標])
//-- Flashウインドウオープン用関数 n4,n6,n7,moz,ie,o6共用
function openFlashWin(flashFileURL,targetName,w,h,x,y){
this.flashFileURL = flashFileURL
this.targetName = targetName
this.w = w ; this.h = h ; this.x = x ; this.y = y
if(!getScreenAvailWIDTH()||!getScreenAvailWIDTH()){this.x=0;this.y=0}
//--x,y座標無指定時のブラウザ座標設定(スクリーン中央へ開く)
if( !this.x && !this.y ){
if(this.x==0||this.y==0)return
this.x = parseInt(( getScreenAvailWIDTH() - this.w )/2,10)
this.y = parseInt(( getScreenAvailHEIGHT() - this.h )/2,10)
}
this.para="" // ウインドウオープン用パラメータ( 幅と高さはブラウザ内寸 )
+" left=" +this.x +",top=" +this.y
+",screenX=" +this.x +",screenY=" +this.y
+",toolbar=" +0 +",location=" +0
+",directories=" +0 +",status=" +0
+",menubar=" +0 +",scrollbars=" +0
+",innerWidth=" +this.w +",innerHeight=" +this.h
+",width=" +this.w +",height=" +this.h
+",resizable=" +1
this.htm ="" // フラッシュ用HTML生成
+"<style type='text/css'>body { margin:0px }</style>"
+" <div style='position:absolute;left:0px;top:0px'>"
+" <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
+" codebase='http://download.macromedia.com/pub/"
+"shockwave/cabs/flash/swflash.cab#version=5,0,0,0'"
+" width="+this.w+" height="+this.h+">"
+" <param name=movie value='"+this.flashFileURL+"'>"
+" <param name=quality value=high>"
+" <embed src='"+this.flashFileURL+"' quality=high "
+" width="+this.w+" height="+this.h
+" type='application/x-shockwave-flash' "
+" pluginspage='http://www.macromedia.com/jp/shockwave/"
+"download/index.cgi?p1_prod_version=shockwaveflash&lang=japanese'>"
+" </embed>"
+" </object>"
+" </div>"
//--サブウインドウオープン
this.win=window.open('',this.targetName,this.para);
this.win.document.write(this.htm)
this.win.document.close()
if(navigator.userAgent.indexOf('MSIE 4.5; Mac')!=-1)//Mace4.5バグ回避
this.win.document.all('flashdoc').style.pixelTop=-28
this.win.moveTo(this.x,this.y)
this.win.focus()
return this.win
}
function getScreenAvailWIDTH(){//-- スクリ−ン有効幅get用関数
if(!!window.screen) return screen.availWidth //n4,n6,moz,ie,o6共用
else return null //上記以外
}
function getScreenAvailHEIGHT(){//-- スクリ−ン有効幅get用関数
if(!!window.screen)return screen.availHeight //n4,n6,moz,ie,o6共用
else return null //上記以外
}
function win_closed(winOj) { //--ウインドウ有無確認関数
var ua = navigator.userAgent
if( !!winOj )
if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 )
return winOj.closed
else return typeof winOj.document != 'object'
else return true
}
Example
<script type='text/javascript'><!--
//-- Flashウインドウオープン用関数 n4,n6,n7,moz,ie,o6共用
function openFlashWin(flashFileURL,targetName,w,h,x,y){
this.flashFileURL = flashFileURL
this.targetName = targetName
this.w = w ; this.h = h ; this.x = x ; this.y = y
if(!getScreenAvailWIDTH()||!getScreenAvailWIDTH()){this.x=0;this.y=0}
//--x,y座標無指定時のブラウザ座標設定(スクリーン中央へ開く)
if( !this.x && !this.y ){
if(this.x==0||this.y==0)return
this.x = parseInt(( getScreenAvailWIDTH() - this.w )/2,10)
this.y = parseInt(( getScreenAvailHEIGHT() - this.h )/2,10)
}
this.para="" // ウインドウオープン用パラメータ( 幅と高さはブラウザ内寸 )
+" left=" +this.x +",top=" +this.y
+",screenX=" +this.x +",screenY=" +this.y
+",toolbar=" +0 +",location=" +0
+",directories=" +0 +",status=" +0
+",menubar=" +0 +",scrollbars=" +0
+",innerWidth=" +this.w +",innerHeight=" +this.h
+",width=" +this.w +",height=" +this.h
+",resizable=" +1
this.htm ="" // フラッシュ用HTML生成
+"<style type='text/css'>body { margin:0px }</style>"
+" <div style='position:absolute;left:0px;top:0px'>"
+" <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
+" codebase='http://download.macromedia.com/pub/"
+"shockwave/cabs/flash/swflash.cab#version=5,0,0,0'"
+" width="+this.w+" height="+this.h+">"
+" <param name=movie value='"+this.flashFileURL+"'>"
+" <param name=quality value=high>"
+" <embed src='"+this.flashFileURL+"' quality=high "
+" width="+this.w+" height="+this.h
+" type='application/x-shockwave-flash' "
+" pluginspage='http://www.macromedia.com/jp/shockwave/"
+"download/index.cgi?p1_prod_version=shockwaveflash&lang=japanese'>"
+" </embed>"
+" </object>"
+" </div>"
//--サブウインドウオープン
this.win=window.open('',this.targetName,this.para);
this.win.document.write(this.htm)
this.win.document.close()
if(navigator.userAgent.indexOf('MSIE 4.5; Mac')!=-1)//Mace4.5バグ回避
this.win.document.all('flashdoc').style.pixelTop=-28
this.win.moveTo(this.x,this.y)
this.win.focus()
return this.win
}
function getScreenAvailWIDTH(){//-- スクリ−ン有効幅get用関数
if(!!window.screen) return screen.availWidth //n4,n6,moz,ie,o6共用
else return null //上記以外
}
function getScreenAvailHEIGHT(){//-- スクリ−ン有効幅get用関数
if(!!window.screen)return screen.availHeight //n4,n6,moz,ie,o6共用
else return null //上記以外
}
function win_closed(winOj) { //--ウインドウ有無確認関数
var ua = navigator.userAgent
if( !!winOj )
if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 )
return winOj.closed
else return typeof winOj.document != 'object'
else return true
}
//--></script>
<form>
<input type = "button"
value = " window.b=new openFlashWin('./1.swf','',200,300) "
onclick= "window.b=new openFlashWin('./1.swf','',200,300)"><br>
<input type = "button"
value = " if(!win_closed(window.b))b.moveTo(10,300) "
onclick= " if(!win_closed(window.b))b.moveTo(10,300) "><br>
<input type = "button"
value = " new openFlashWin('./1.swf','',120,100,100,100) "
onclick= "new openFlashWin('./1.swf','',120,100,100,100)"><br>
</form>クリックするとFlashウインドウが<br>
指定した位置(無指定は中央)とサイズでオープンします。