我受到了Instapaper bookmarklets的启发,它允许将页面添加到Instapaper,而无需单独的弹出窗口,也无需重新加载整页。我想将这个想法与用于书签页面的Delicious bookmarklet相结合。
jQuery Colorbox plugin支持将iframe内容加载到colobox弹出框中,因此它似乎是一个很好的起点。我拼凑了几个bookmarklet来获取下面的代码,这似乎是一个良好的开端,直到我添加了“$.fn.colorbox ...”行。我似乎无法打开Colorbox。我甚至尝试将其简化为打开Google hopepage,但也没有运气:
javascript:
function iprl5(){
var d=document,z=d.createElement('scr'+'ipt'),y=d.createElement('scr'+'ipt'),x=d.createElement('scr'+'ipt'),b=d.body,l=d.location,t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');
try{
if(!b)
throw(0);
d.title='(Saving...)%20'+d.title;
x.setAttribute('src','http://cachedcommons.org/cache/jquery/1.4.2/javascripts/jquery.js');
y.setAttribute('src','http://cachedcommons.org/cache/jquery-colorbox/1.3.9/javascripts/jquery-colorbox.js');
b.appendChild(x);
b.appendChild(y);
$.fn.colorbox({href:'http://www.delicious.com/save?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&v=5&',open:true,iframe:true});
}
catch(e){
alert('Please%20wait%20until%20the%20page%20has%20loaded.');
}
}
iprl5();
void(0)
答案 0 :(得分:1)
脚本在一个单独的线程中加载。您需要等到脚本加载后再使用它。通常是这样的:
var checkIfLoaded = function(){
if($.fn.colorbox){
// continue your processing
}else{
window.setTimeout(200, checkIfLoaded);
}
}
checkIfLoaded();