玩一玩javascript的bookmarklet

來源:互聯網
上載者:User

之前寫過一篇如何為豆瓣FM寫一個chrome的歌詞外掛程式 ,luoluo牛告訴我,其實可以用bookmarklet實現。

阮一峰先生的一篇部落格 介紹了怎麼寫bookmarklet,所以我這裡不多談。

我身邊住著愛國者(@buptpatriot),每天都上google,它的首頁一直是美國人的google:


恩,今天我就用bookmarklet把google的logo換一下。

這裡要用到javascript的document.createElement()方法和document.appendChild()方法。

我的bookmarklet(很簡單):

javascript:(function()%7Bjavascript%3Avar%20my_div%20%3D%20document.createElement('div')%3Bmy_div.style.width%3D'600px'%3Bmy_div.style.height%3D'217px'%3Bmy_div.style.backgroundColor%20%3D%20'red'%3Bmy_div.style.zIndex%20%3D%20'90'%3Bmy_div.style.position%20%3D%20'relative'%3Bmy_div.style.margin%3D'-600px%20auto'%3Bmy_div.innerHTML%3D%22%3Cimg%20src%3D'http%3A%2F%2Fwww.worldatlas.com%2Fwebimage%2Fflags%2Fcountrys%2Fzzzflags%2Fcnlarge.gif'%20width%3D600px%20height%3D217px%5C%3E%22%3Bdocument.body.appendChild(my_div)%7D)()

【附】bookmarklet線上產生器: http://mrcoles.com/bookmarklet/

儲存成書籤,開啟google,點一下這個書籤,哦,有效果了-->向愛國者致敬。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.