複数ページ用の window.onload ハンドラのコードを 1 ファイルにまとめる jQuery plugin を書きました。WEB + DB PRESS 60 号に載っていた URL Dispatcher のコードを書き換えたものです。
使い方
$.route() の引数に、ページの URL と window.onload で実行する内容のペアを渡します。下記の例では index.html または / で終わる URL と、index2.html で終わる URL それぞれの window.onload ハンドラを設定しています。
$.route( { path: /(index\.html|\/)$/, func: function() { $("#output").html("this is /index.html or /"); } }, { path: /index2\.html$/, func: function() { $("#output").html("this is /index2.html"); } } );