嗨我想創建一個書籤 - 讓它打開一個網頁找到一個鏈接到該網頁上的下載,然後關閉該網頁。除非有更好的方法去做,否則我打開頁面,調用ready(我認爲這是非workint的部分),然後搜索下載鏈接。導入jQuery的代碼取自:http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/jQuery準備書籤
javascript:(function() {
var v = "1.3.2";
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initMyBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
}
else {
initMyBookmarklet();
}
function initMyBookmarklet() {
var ytm = window.open('http://example.com');
jQuery(document).ready(function() {
var div = ytm.document.getElementById("dl_link");
var links = ytm.document.getElementsByTagName('a');
var dl = links[1];
window.open(dl);});
ytm.close();
}
})();
謝謝提前!
爲什麼這麼痛苦的老版本的jQuery? – 2013-04-08 17:37:34
@MattBall複製/粘貼。 – 2013-04-08 17:40:57
@MattBall它也是jQuery必需的最低版本。如果該窗口已經有一個更新版本的jQuery導入,它就會使用它。 – Buck 2013-04-08 17:58:32