[英]How to load external css, js and append a div to the DOM from a bookmarklet?
我正在嘗試構建執行以下操作的書簽:
1.)加載位於我服務器上的外部js(完成)
javascript:function%20loadScript(scriptURL)%20{%20var%20scriptElem%20=%20document.createElement('SCRIPT');%20scriptElem.setAttribute('language',%20'JavaScript');%20scriptElem.setAttribute('src',%20scriptURL);%20document.body.appendChild(scriptElem);}%20loadScript('http://127.0.0.1/main.js?x='+Math.random());
2.)此外部javascript依次加載jquery和jquery ui,然后將div添加到當前站點DOM中。 (無法使它正常工作)
function loadScripts(scriptURL) {
var scriptElem = document.createElement('SCRIPT');
scriptElem.setAttribute('language', 'JavaScript');
scriptElem.setAttribute('src', scriptURL);
void(document.body.appendChild(scriptElem));
}
loadScripts('http://127.0.0.1/js/jquery-1.3.2.min.js');
loadScripts('http://127.0.0.1/js/jquery-ui-1.7.2.custom.min.js');
var head = document.getElementsByTagName('head')[0];
$(document.createElement('link')).attr({type: 'text/css', href: 'http://127.0.0.1/css/redmond/jquery-ui-1.7.2.custom.css', rel: 'stylesheet'}).appendTo(head);
$(document).ready(function(){
div = $("<div>").html("Loading......");
$("body").prepend(div);
});
我遇到的問題是我無法在div后面附加一個特定的id,其想法是使用jqueryui的dialog()函數,以便在我在其中使用bookmarklet的任何站點上都出現可調整大小的可移動對話框。 。
$("#dialog").dialog();
可以想象,我需要將我的內容加載到特定的div中,這樣我才不會弄亂加載書簽的網站的設計。
3)剛剛打開的對話框包含一個基本解析頁面的遠程php文件的內容。
腳本完成后,我只需要將其加載到要構建的對話框中即可。
請幫忙,因為我真的很堅持! 謝謝。
這有幫助嗎? 這是給您帶來麻煩的部分嗎?
$("<div id='id'></div>").html("Loading......");
jQuery文檔說:
所有HTML的格式都必須正確,否則可能無法在所有瀏覽器上正常工作。 這包括
$("<span>")
可能不起作用,但$("<span/>")
將起作用的情況(請注意XML樣式的斜杠)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.