Bookmarklet
在不使用网页的情况下,也可以使用JavaScript 控制浏览器,所用的技术称为bookmarklet
bookmarklet 与其他JavaScript 代码不太一样,因为它们有一个重要而有意思的格式限制:它们必须写在一行中。要使用分号把命令连在一起。
使用bookmarklet 改变你查看别人页面的方式——这正是bookmarklet 的特殊之处
Example: Firefox
Create a new bookmark with code in location part.
- Change Background Color
javascript:void(document.body.style.background='#FFF');
- List all images
javascript:(function(){var iWin,i,t='',di=document.images;for(i=0;i<di.length;i++){if(t.indexOf(di[i].src)<0){t+='<tr><td><img src='+di[i].src+'/></td><td>'+di[i].height+'</td><td>'+di[i].width+'</td><td>'+ di[i].src+'</td></tr>';}}if(t==''){alert('No images!');}else{iWin=window.open('','IW','width=800,height=600,scrollbars=yes');iWin.document.body.innerHTML='<table border=1 cellpadding=10 cellspacing=0><tr><th>Image</th><th>Height</th><th>Width</th <th>URL</th></tr>'+t+'</table>';}})();
- Send this page via email
javascript:(function(){location.href='mailto:?SUBJECT='+document.title+'&BODY='+escape(location.href)+'\r'+window.getSelection();})();