ホームページ用電灯スイッチ(?)です。documentオブシェクトの中の背景色を指定するプロパティdocument.bgColorを使っています。スイッチをおすと背景色がon/offして電灯をつけたり消したりしているようにみえます(^^;?。 Mac版NN2.0とUNIX版3.0までのバージョンにあった背景色バグの回避文を入れてありますが現在ははずしても大丈夫でしょう。
応用:色名を'pink'とか'red'とか'123456'などに取り替えて遊んでみましょう(^^)/。背景色と同じ色を文字の色に使えばスイッチのon/offごとに読める文字を替えることができます。
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
//エラーダイアログを出ないようにするNN3.0~
window.onerror = null;
takuwinr = null;//リモコンウインドウ
sw = 0 ;//スイッチon/offフラグ
//bgColorバグ回避--ここから
function BGCLbug(){
bw0=navigator.appVersion.charAt(0);
bwV=navigator.appVersion;
if ((bw0<'3'&&bwV.indexOf('Mac')!=-1)||
(bw0<'4'&&bwV.indexOf('X11')!=-1)){
//ここでウインドウオープン
nwin =window.open("","",'width=800,height=800');
//ここでクローズ
nwin.close();
}
}
//bgColorバグ回避--ここまで
//ふきだし
function fukidashi(){
//DP2,3 PS2 Zaurus を除外
if( navigator.userAgent.indexOf("Planetweb/v1") == -1 ||
navigator.userAgent.indexOf("AveFront/2") == -1 ||
userAgent.indexOf("DreamPassport/") == -1 ||
userAgent.indexOf("sharp pda browser/") == -1 ){
takuwin = window.open('','fu','width=150,height=150');
takuwin.document.write("<body bgcolor='#000000' text='#888888'>");
takuwin.document.write("あれ〜?まっくらだぞ。スイッチはどこだ〜?");
takuwin.document.close();
if(navigator.appVersion.charAt(0)>=3)takuwin.focus()
}
}
//NN2などimageをサポートしていないブラウザでエラーがでないように分岐
if ( document.images ){
//画像の事前読み込み
swbton0 = new Image();
swbton0.src = 'BTON0.GIF';
swbton1 = new Image();
swbton1.src = 'BTON1.GIF';
}
//リモコンウインドウ
function remote() {
takuwinr=window.open('','ron','width=140,height=100');
takuwinr.opener=self;
takuwinr.document.write("<body bgcolor='543210' text='#888888'>");
takuwinr.document.write("<center><nobr><font size=1>[リモコンスイッチ]</nobr>");
takuwinr.document.write('<a href="javascript:opener.takuon()">');
takuwinr.document.write("<img src='BTON0.GIF' name='swrbutton' border='0'></a>");
takuwinr.document.write('<br>on/off</font></center>');
takuwinr.document.close();
if(navigator.appVersion.charAt(0)>=3)takuwinr.focus()
}
function takuon(){
if(sw==0){
if( document.images )
document.swbutton.src = swbton1.src;
document.bgColor="#ffffff";
BGCLbug();
sw = 1;
takuwin=window.open('','fu','width=150,height=150');
takuwin.document.write("<body bgcolor='ffffff' text='#000000'>");
takuwin.document.write("<font size=5>おっ!<br>ついた<br>(^^)/</font>");
takuwin.document.close();
if(navigator.appVersion.charAt(0)>=3)takuwin.focus()
//リモコン用
if( document.images && window.takuwinr )
takuwinr.document.swrbutton.src = swbton1.src;
} else {
if( document.images )
document.swbutton.src = swbton0.src;
document.bgColor="#000000";BGCLbug();
sw=0;
takuwin=window.open('','fu','width=150,height=150');
takuwin.document.write("<body bgcolor='#000000' text='#888888'>");
takuwin.document.write("あれ〜?まっくらだぞ。スイッチはどこだ〜?");
takuwin.document.close();
if(navigator.appVersion.charAt(0)>=3)takuwin.focus()
//リモコン用
if( document.images && window.takuwinr )
takuwinr.document.swrbutton.src = swbton0.src;
}
}
//-->
</script>
</head>
<body bgcolor ="#000000" text ="#000000"
link ="#ff27ec" alink ="#ffe922" vlink="#984eff">
<form>
<input type="button" value="on/off"
onClick="takuon()">NN3.x以外用ボタン
</form>
<br><br><br>
<center>
<font size=7 face="Osaka,MS Pゴシック" color="#ffffff">
暗いよ〜</font>
<a href="javascript:takuon()">
<img src='BTON0.GIF' name='swbutton' border="0"></a>
<font size=7 face="Osaka,MS Pゴシック" color="#000000">
じゃ〜ん</font>
<br><br><br><br><br><br><br><br><p>
<form>
<input type="radio" onClick="remote()">
リモコンスイッチ(^^)/NN3以上用
</form>
</body>
</html>
使用している画像:
BTON0.GIF
BTON1.GIF
| CONTENTS
| PART1 これだけ知っていれば大丈夫
| PART2 サンプルの紹介
| PART3 JavaScript言語仕様
| PART4 JavaScriptクイック書式一覧
| PART5 JavaScriptサイト
| オンラインサポートページ(回線をつないでください)