ポップアップウインドウを開く
ポップアップウインドウを開く設定をするたびにJavaScriptを記述するのはメンテナンス性に欠ける。
1つのJavaScriptファイルにその機能を集約させポップアップウインドウとして開くURLを簡単に集約できるスクリプトを作る。
//ポップアップウインドウとして開くウインドウリストを配列にセットする var windowList = new Array(); windowList.push({ url : "popup01.html", window_name : "popup_window", options : { width : 800, height : 600, location : "yes", scrollbars : "yes", resizable : "yes", top : 100, left : 100 } }); MyLib.event.observe(window, "load", openPopupWindow, false); function openPopupWindow(){ var list; var anchor; //全てのa要素を取得する var anchors = document.getElementsByTagName("a"); //a要素のhref属性とwindowListのurlプロパティの値が一致するかどうかをmatchメソッドを使用し照合する if(typeof(windowList) != "undefined"){ for(var i=0; anchor=anchors[i]; i++){ for(var j=0; list=windowList[j]; j++){ if(anchor.href.match(new RegExp(list.url, "i"))){ anchor.list = list; //ポップアップウインドウを開く MyLib.event.observe(anchor, "click", function(event){ var options = ""; for(var index in this.list.options){ options += index + "=" + this.list.options[index] + ","; } options = options.replace(/,$/, ""); window.open(this.href, this.list.window_name, options).focus(); MyLib.event.stop(event); }, false); break; } } } } }