このページの対象読者
このページはBookmarkletの作成にあたって必要となるJavascriptの中で主要なものを説明しているサイト開発者向けのページです。ブックマークレット利用者の方は、ブックマークレットとは?をご覧ください。
ページ移動
方式1
document.locationにURLをセットする方式
document.location = URL;
サンプル
document.location='http://hoge.com/?url='+escape(window.location);
方式2
window.openで開く方式
window.open(URL);
サンプル
eval(); または undefined; を末尾に付けているのに何か意味があるはずであるが不明(未実験)
window.open('http://www.usamimi.info/~ryouchi/movie/index.php?url='+escape(location.href));eval();
window.open('http://www.vid-dl.net/?url='+encodeURIComponent(location.href)+'&r=bm1', null);undefined;
window.open('http://dohow.jp/php-bin/test_posting.php?m=regist&t='+encodeURI(document.title)+'&u='+encodeURI(location.href), '_blank', 'width=560,height=360,resizable=1,scrollbars=1');undefined;
window.open('http://dohow.jp/php-bin/test_decodeuri.php?m=regist&t='+encodeURI(document.title)+'&u='+encodeURI(location.href), '_blank', 'width=560,height=360,resizable=1,scrollbars=1');undefined;
現在参照しているページURLの取得
window.location
location.href
動的にjsファイルをインクルードする
function loadScript(scriptURL) { var scriptElem = document.createElement('SCRIPT'); scriptElem.setAttribute('language', 'JavaScript'); scriptElem.setAttribute('src', scriptURL); document.body.appendChild(scriptElem);}loadScript('http://westciv.com/mri/theMRI.js');
document.write() でインクルード出来ないのだろうか?未実験。
チェックボックスのすべてにチェックをつける
(function () {for (i=0;i<document.all.length;i++) {obj = document.all(i);if (obj.name=='pack_check') {obj.checked=true;}if (obj.name!='pack_check') {obj.checked=false;if (obj.type=='image') {window.alert(obj.src);if (obj.src.indexOf('/images/b_34.gif')>0) {/*window.alert('button');*/obj.click();}}}}})()
その他
意図を忘れたけど、何か使えるかも
sk=open('','Z6');el=document.getElementsByTagName('option');el2=document.getElementsByTagName('input');with(sk.document){write('<base target=_blank>');write('<table border=1>');var n=0;for(i=0;i<el2.length;i++){if(el2[i].name=='fi'){var fi=el2[i].value}}for(i=0;i<el.length;i++){if(el[i].value){n++;write('<tr><td>');write('<a href=\''+'http://www.kokoroplanet.jp/diary_view.kp?fi='+fi+'&bi='+el[i].value+'\' target=\'_blank\'>'+el[i].innerText+'</a><BR>');write('</td></tr>');}}write('</table>');if(n>15)n=15;sk.window.moveTo(0,0);sk.window.resizeTo(600,45*n);void(close());}
