我有幾個要點,我需要包括在網站上的帖子展示源代碼。目前,我正在使用腳本標記在HTML中的各個位置插入多個要點中的每一個,但是,這將是一個阻塞呼叫。那麼,有沒有辦法動態加載要點並及時粘貼特定的點。懶惰加載github gist文件在網站上顯示源代碼
我試過類似下面: -
<html>
<body>
<div id="bookmarklet_1.js"></div>
<div id="bookmarklet_2.js"></div>
<div id="bookmarklet_3.js"></div>
var scriptMap = {'bookmarklet_1.js' : 'https://gist.github.com/892232.js?file=bookmarklet_1.js',
'bookmarklet_2.js' : 'https://gist.github.com/892234.js?file=bookmarklet_2.js',
'bookmarklet_3.js' : 'https://gist.github.com/892236.js?file=bookmarklet_3.js'};
var s, scr, holder;
for(s in scriptMap){
holder = document.getElementById(s);
scr= document.createElement('script');
scr.type= 'text/javascript';
scr.src= scriptMap[s];
holder.appendChild(scr);
}
</script>
</body>
</html>
以上沒有工作對我來說,似乎每個腳本是做一個document.write
內部寫CSS和索裏的代碼。有沒有人嘗試過這或之前工作?
這個URL被拋出服務器錯誤。 – 2012-06-16 20:38:01
謝謝。回答更正新的網址。我沒有看到大量的流量,所以我放棄了域名。該服務仍然有效;將無限期地託管在heroku的免費套餐上。或從github複製代碼並自己託管它。 – colllin 2012-06-21 16:08:56
也可以從github項目(https://github.com/colllin/urlspoiler)中竊取相關代碼, – colllin 2014-09-11 20:42:52